Forum Moderators: open

Message Too Old, No Replies

Mulitiply the values entered by user using dom

         

ravii

9:19 am on Apr 24, 2009 (gmt 0)

10+ Year Member



hello,

here is example with 3 cells

when the user click on the ANSWER button then the values should get multiply and view the answer
but the problem is i can't get the value which i entered in the text box

please tell me what the wrong is

here is the code

<html>
<head>

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

var q=y*z;
alert(y);
alert(z);
alert(q);
}
</script>
</head>

<body>

<table id="myTable" border="1">
<?php
for($r=1;$r<=3;$r++)
{
echo'<tr>
<td>10</td>
<td><input type="text" id="txt"/></td>
<td><input type="button" onClick="cell('.$r.')" value="Answer"></td>
</tr>';
}
?>

</table>
<br />
</body>
</html>

whoisgregg

4:07 pm on Apr 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello ravii,

All the code is correct, the only issue is how PHP is generating the values passed to the cell function. Because javascript is 0-indexed, your PHP loop should start at 0 instead of 1 for them to line up right.

for($r=0;$r<3;$r++) 

rocknbil

4:45 pm on Apr 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This question was addressed here [webmasterworld.com] and a working solution was posted. Sorry I didn't reply to your PM ravii, you introduced other factors (ajax and some other things) and I wasn't able to think of a solution in the time I have alotted to my daily "WebMasterWorld" research. :-)