Forum Moderators: open

Message Too Old, No Replies

pass the Text box value and the price value using DOM

         

ravii

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

10+ Year Member



hello

I need to alert the text what i entered in the text box and need to alert the price value which is to the side of the $ symbol

If remove the $ symbol and alert the price then i can see the Price
but i need the $ symbol there but in alert there is no need to pass the $ symbol only pass the price i.e 1000

here is my code


<html>
<head>
<script type="text/javascript">
function cell(i)
{
//var x=document.getElementById('myTable').rows[0].cells;
//alert(x[0].innerHTML);
var x=document.getElementById('myTable')
var y = x.rows[i].cells[1].firstChild.value;
var z = x.rows[i].cells[0].firstChild[getElementById(txt1).value];

alert(y);
alert(z);
}
</script>
</head>
<body>
<?php
$price=1000;
echo'<table id="myTable" border="1">';
for ($i=0; $i<3; $i++)
{
echo'<tr>
<td>$<input type="text" id="txt1" value="'.$price.'" disabled/></td>
<td> <input type="text" id="txt"/></td>
<td> <input type="button" onClick="cell('.$i.')" value="Alert"></td>
</tr>';
}
echo'</table>';
?>
</body>
</html>

astupidname

5:50 am on Jan 30, 2009 (gmt 0)

10+ Year Member



You have some duplicate id problems, as you are assigning the same id's to elements in 3 different rows. Also, rather than accessing the input's values via row and cell, why not just access them by id (after fixing the php 'for' loop to assign unique id's):

<html>
<head>
<script type="text/javascript">
function cell(i) {
var y = document.getElementById('txtA'+i).value;
var z = document.getElementById('txtB'+i).value;
alert(y);
alert(z);
}
</script>
</head>
<body>
<?php
$price=1000;
echo'<table id="myTable" border="1">';
for ($i=0; $i<3; $i++) {
echo'<tr>
<td>$<input type="text" id="txtA'.$i.'" value="'.$price.'" disabled/></td>
<td> <input type="text" id="txtB'.$i.'"/></td>
<td> <input type="button" onclick="cell('.$i.')" value="Alert"></td>
</tr>';
}
echo'</table>';
?>
</body>
</html>