|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a form with three select fields. Each of the options has a value, which is a price. How do I have javascript read the values of the three selected options? I want it to read them and total the prices.
TIA, Ben |
|
#2
|
|||
|
|||
|
price1 = form.elements[0].options[0].value
price2 = form.elements[0].options[1].value price3 = form.elements[0].options[2].value . . price5 = form.elements[1].options[1].value . . price9 = form.elements[2].options[2].value You will need to adjust the array index of elements to match your form. The index is assigned by how the elements appear in the code, not on the form. Or you can replace elements[x] with the name of the element if you gave it one. Each of the three select fields will have however many options you assign accessed by options[x] starting with options[0]. Russ <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by FerretComp: I have a form with three select fields. Each of the options has a value, which is a price. How do I have javascript read the values of the three selected options? I want it to read them and total the prices. TIA, Ben[/quote] |
|
#3
|
|||
|
|||
|
Is there a way to get the value for the option the user has selected?
Ben |
|
#4
|
|||
|
|||
|
To get the value that the user selects from the selectbox you can do it like this:
price = document.formname.selectboxname.options[document.formname.selectboxname.selectedIndex].value; Spookster ------------------ Visit the WSAbstract Help Forum for your Javascript, DHTML, or General Web Design Questions |
|
#5
|
|||
|
|||
|
Thanks, that really cleans up my code a lot.
|
|
#6
|
|||
|
|||
|
You can even shorten that down by using a variable:
theForm = document.formname.selectboxname price = theForm.options[theForm.selectedIndex].value; Spookster ------------------ Visit the WSAbstract Help Forum for your Javascript, DHTML, or General Web Design Questions |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > getting the value of a selected index |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|