...

View Full Version : Adding numbers linked to data



tjc19999
06-25-2004, 09:06 AM
My code so far is as follows:

<html>
<head>
<script type="text/javascript">
function put()
{
txt=document.forms[0].myList.options[document.forms[0].myList.selectedIndex].text
document.forms[0].favorite.value=txt
}
</script>
</head>

<body>
<form>
Select your power supply:
<select name="myList" onclick="put()">
<option>450 watt power +$0.00</option>
<option>550 watt power +$15.00</option>
<option>650 watt power +$50.00</option>
</select>
<br /><br />
Your selection is: <input type="text" name="favorite" size="20">
</form>
</body>

</html>

--------------------------
I want to link numbers to each option then display the number linked to the option instead of the whole option. This script is working. And I hope to be able to add many options to get a final value. Thanks for any help available.

glenngv
06-25-2004, 09:33 AM
function put(objSel)
{
objSel.form.favorite.value=objSel.options[objSel.selectedIndex].value;
}
...
<select name="myList" onclick="put(this)">
<option value="">Choose one</option>
<option value="450">450 watt power +$0.00</option>
<option value="550">550 watt power +$15.00</option>
<option value="650">650 watt power +$50.00</option>
</select>

See how the function can be shortened and be made flexible by using function parameters.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum