hello.......
i have a table that stores the quantity , unitprice , total values in the text fields......... actually this total column should be calculated automatically...when i use a onFocus function on tht text field i.e total=qty*unitprice ....... this code works fine when the text field in all the rows have different names .... like its qty1 for the first row....qty2 for the second row...... but i want to have all the columns to have the same name ...like only qty,unitprice,total...... i need the naming to be this way as i have to store these into database and all.....if i use different names...then the other part of my code becomes difficult....how do i perform the calculation when the names are same....
here is my code............
<HTML>
<HEAD>
<script>
function total()
{
var qty= document.form1.qty.value;
var up=document.form1.up.value;
var total=qty*up;
document.form1.total.value=total;
}
</script>
</HEAD>
<BODY>
<form name="form1">
<table border="1">
<tr>
<th> S.NO </th>
<th> Qty </th>
<th> Unit price </th>
<th> Total </th>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
<td> <input type="text" name="up"> </td>
<td> <input type="text" name="total" onFocus="total()"> </td>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
<td> <input type="text" name="up"> </td>
<td> <input type="text" name="total" onFocus="total()"> </td>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
<td> <input type="text" name="up"> </td>
<td> <input type="text" name="total" onFocus="total()"> </td>
</tr>
</table>
</form>
</BODY>
</HTML>
this code displays an error...... cud anyone please tell me the error and how to do this....