Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 4th, 2003, 09:36 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #2 (permalink)  
Old December 5th, 2003, 01:09 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old December 5th, 2003, 01:27 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Or, alternatively, set the value of each item equal to the selected index....


Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #4 (permalink)  
Old September 9th, 2005, 02:56 PM
KD KD is offline
Registered User
 
Join Date: Sep 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #5 (permalink)  
Old September 9th, 2005, 03:00 PM
KD KD is offline
Registered User
 
Join Date: Sep 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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




Reply With Quote
  #6 (permalink)  
Old September 12th, 2005, 11:42 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

http://p2p.wrox.com/topic.asp?TOPIC_ID=34638

--

Joe (Microsoft MVP - XML)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
z-index problem with select showing through div crmpicco CSS Cascading Style Sheets 3 July 4th, 2008 07:00 AM
xslt: pass index of array EefjeC XSLT 1 July 2nd, 2007 06:31 AM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
How to get index value in combo box populate BOOK: Beginning Access VBA 1 June 1st, 2005 06:22 AM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM



All times are GMT -4. The time now is 05:59 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.