PDA

View Full Version : Mulitiply the values entered by user using java script and php


swetha123
04-24-2009, 09:25 AM
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>

davidj
04-24-2009, 10:18 AM
suggest you name your formfields with a unique name