Hi,
You getting 'NAN' because you didn't change all of the options. Also, you will be unable to get the 1st calculation without selecting and reselecting because of the onchange handler.
Why aren't you using a function? Something like:
Code:
function doit(formObj, selA, selB)
{
formObj.summa.value = parseFloat(selA.options[selA.selectedIndex].value)
+ parseFloat(selB.options[selB.selectedIndex].value)
}
The example code below demonstrates the different ways you can call the above function. Note: if you cut & paste this, do not use all of the methods.
Code:
<form>
<select name="a" onchange="doit(this.form,this.form.a,this.form.b)">
<option value='0'>a</option>
<option value='80'>b</option>
</select>
<select name="b" onchange="doit(this.form,this.form.a,this.form.b)">
<option value='10'>c</option>
<option value='180'>d</option>
</select>
<input type="text" name="summa" onfocus="doit(this.form,this.form.a,this.form.b)">
<input type="button" value='do it' onclick="doit(this.form,this.form.a,this.form.b)">
</form>
Vinny
Bookmarks