Forum Moderators: open

Message Too Old, No Replies

Pass the Input text value in a TD cell using DOM

         

ravii

11:45 am on Jan 29, 2009 (gmt 0)

10+ Year Member



hello ,

I need to alert the value entered in the text box,which is in TD cell, using DOM

can any one tell how please
here is the code with out a text box which is working

<html>
<head>
<script type="text/javascript">
function cell()
{
var x=document.getElementById('myTable').rows[0].cells;
alert(x[0].innerHTML);
}
</script>
</head>
<body>

<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br />
<input type="button" onclick="cell()" value="Alert first cell">

</body>
</html>

here is what i need

<html>
<head>
<script type="text/javascript">
function cell()
{
var x=document.getElementById('myTable').rows[0].cells;
alert(x[1].firstChild.Value);
}
</script>
</head>
<body>

<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td><input type="text" id="txt"></td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br />
<input type="button" onclick="cell()" value="Alert first cell">

</body>
</html>
but i can't see the output if anything wromg please tell me

thanks
Swetha

Fotiman

7:12 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, for one thing JavaScript is case sensitive, so "Value" will not work (it would need to be "value"). However, instead of firstChild, maybe you could use getElementsByTagName('input')[0].value?