 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 4th, 2003, 09:36 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Select Box: Pass Literal instead of Index
I have a Select box for Education on a multi-page form, where I am passing name-value pairs to my final "Thank You" page.
I would like to pass the literal value (e.g., "College Graduate"), rather than the index value (e.g., "2") on to the final page.
How do I do this?
When: myForm.education.value = 2 & myForm.education.selectedIndex = 2
I tried using a Switch command, e.g.,
switch(myForm.education.value){
switch(myForm.education.selected){
switch(parseInt(myForm.education.value)){
switch(myForm.education.selectedIndex){
case 0:
myForm.education.value = "High School Graduate";
break;
case 1:
myForm.education.value = "Some College";
break;
case 2:
myForm.education.value = "College Graduate";
break;
etc.
but either the code was not executed at all, or the code was executed and myForm.education.value was set to blank or null, not to the literal.
I'm sure there is a way to do this, but I can't figure out how.
Any help would be appreciated.
Thanks.
|
|

December 5th, 2003, 01:09 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
By design, the value(s) of the option(s) (not the option index) in a select are what what get passed as the data when the form is posted. The easiest way to solve this would be to fill the value of the option with the same string as the text part of it. If you need to have the value of the option be numeric, then you'll have to find another way. Perhaps you could create a hidden form input field, and when the form is submitted, the currectly selected option's text is put in the hidden field and you get value of that instead of the select input value.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

December 5th, 2003, 01:27 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Or, alternatively, set the value of each item equal to the selected index....
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

September 9th, 2005, 02:56 PM
|
|
Registered User
|
|
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi ,
I have the same problem as WebDevel has,if u solved the problem culd u pls let me knw how u did?
I tried assigning the text value to the hidden field while submit, but still it is giving the same index value instead of text value.
thanks
|
|

September 9th, 2005, 03:00 PM
|
|
Registered User
|
|
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have a Select box for Admin on a form the changes shuld get saved in database, where I am passing name-value pairs to form bean "AdminData" .
I would like to pass the literal value (e.g., "College Graduate"), rather than the index value (e.g., "2").
How do I do this?
I tried assigning the text value to the hidden field while submit, but still it is giving the same index value instead of text value.
thanks
|
|

September 12th, 2005, 11:42 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
|
|
 |