I wonder if you can help me.
I have a web page with a form which has dynamic named fields for size, quantity, price. The reason they are dynamic is that there could be one occurance of them, or 10 occurrances, as it depends how many options they picked on a previous page. they are named in the following way. size0, size1, size2, size3, price0, price1, price2, etc.
I have tried to write a function to work out the value of price, which is size*quantity
here is my code
function doMath(i) {
c = “document.form1.price”+i+”.value”
a = “document.form1.size”+i+”.value”
b = “document.form1.quantity”+i+”.value”
document.form1.price+i+.value = eval(a + ‘*’ + b)
}
and from the page the form elements look like this
<select name=”size[<%=i%>]” onchange=”doMath(‘<%=i%>’)”>
<option value=”0″>Select</option>
<option value=”6″>7.5"x5" @ £6.00</option>
<option value=”8″>10"x5" @ £8.00</option>
</select>
the <%=i%> is changed to 0, 1, 2, 3, etc on the servergiving size0, size1 and doMath(‘0’), doMath(‘1’) etc.
I can get the function to work for the first line if I change the last line to
document.form1.price0.value = eval(a + ‘*’ + b)
So I suppose I need to know how to get the value i I pass to the function in instead of the 0 above?
Not sure if this is clear but hope you can help
Richard