Please Help!!! - I'm having trouble with changing the value of an <input>
here's my problem... I want to create several <select> menus, having each option inside them assigned an integer value, with an <input> that contains the total of all of the selected options.... here's example code if anyone can help
<html>
<head><title></title>
<script language='javascript'>
var drivevalue =0;
var monitorvalue = 0;
function compute(obj) {
obj.expr.value = (drivevalue + monitorvalue);
}
function calculate(obj) {
drivevalue = obj.drivelist.selectedIndex.value;
monitorvalue = obj.monitorlist.selectedIndex.value;
compute(obj);
}
</script>
<body bgcolor='#ffffff' text='#000000' link='#800000' vlink='#800000'>
<form>
<select name="drivelist" size="1">
<option value="100">Big Drive</option>
<option value="50">Small Drive</option>
</select>
<select name="monitorlist" size="1">
<option value="200">Big Monitor</option>
<option value="150">Small Monitor</option>
</select>
<input type="button" value="compute" onClick="calculate(this.form)">
<INPUT TYPE=text NAME="expr" SIZE=20>
</form>
</body>
</html>
thanks for any help....
----------
Best Wishes and Tuna Fishes
lifeform posted this at 21:25 — 7th September 1999.
They have: 7 posts
Joined: Aug 1999
hey thanks!!! I got it to work a different way... but only for I.E. 5.0.... if ya wanna see it, it's
http://www3.sympatico.ca/lifeform7
it's in the products section under customize a system....
----------
Best Wishes and Tuna Fishes
elara posted this at 23:52 — 7th September 1999.
They have: 112 posts
Joined: Apr 1999
lifeform,
You have missed two important things in the script.
First of all, the options value should be accessed like this:
obj.drivelist.options[obj.drivelist.selectedIndex].value
Secondly, the value obtained from the options are strings, so you need to convert them into integers with the parseInt() function.
The modified script is at below.
<html>
<head><title></title>
<script language='javascript'>
var drivevalue =0;
var monitorvalue = 0;
function compute(obj) {
obj.expr.value = (drivevalue + monitorvalue);
}
function calculate(obj) {
drivevalue = parseInt(obj.drivelist.options[obj.drivelist.selectedIndex].value);
monitorvalue = parseInt(obj.monitorlist.options[obj.monitorlist.selectedIndex].value);
compute(obj);
}
</script>
<body bgcolor='#ffffff' text='#000000' link='#800000' vlink='#800000'>
<form>
<select name="drivelist" size="1">
<option value="100">Big Drive</option>
<option value="50">Small Drive</option>
</select>
<select name="monitorlist" size="1">
<option value="200">Big Monitor</option>
<option value="150">Small Monitor</option>
</select>
<input type="button" value="compute" onClick="calculate(this.form)">
<INPUT TYPE=text NAME="expr" SIZE=20>
</form>
</body>
</html>
Hope this helps...
Later.
Joe Thong
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.