Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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
 
Old December 4th, 2003, 09:36 PM
Registered User
 
Join Date: Dec 2003
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.
 
Old December 5th, 2003, 01:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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.
 
Old December 5th, 2003, 01:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.
 
Old September 9th, 2005, 02:56 PM
KD KD is offline
Registered User
 
Join Date: Sep 2005
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

 
Old September 9th, 2005, 03:00 PM
KD KD is offline
Registered User
 
Join Date: Sep 2005
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




 
Old September 12th, 2005, 11:42 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)





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





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