SunQuest
           HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 21st, 2000, 06:24 PM
FerretComp FerretComp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 65 FerretComp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to 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

Reply With Quote
  #2  
Old June 21st, 2000, 09:33 PM
rkmarcks rkmarcks is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 81 rkmarcks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to rkmarcks
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]


Reply With Quote
  #3  
Old June 21st, 2000, 10:02 PM
FerretComp FerretComp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 65 FerretComp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to FerretComp
Is there a way to get the value for the option the user has selected?
Ben

Reply With Quote
  #4  
Old June 21st, 2000, 11:47 PM
Spookster Spookster is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Posts: 84 Spookster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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

Reply With Quote
  #5  
Old June 22nd, 2000, 03:37 PM
FerretComp FerretComp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 65 FerretComp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to FerretComp
Thanks, that really cleans up my code a lot.

Reply With Quote
  #6  
Old June 22nd, 2000, 10:05 PM
Spookster Spookster is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Posts: 84 Spookster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > getting the value of a selected index


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway