permaculture playing cards*
The moose likes HTML, CSS and JavaScript and the fly likes Changing code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Changing code " Watch "Changing code " New topic
Author

Changing code

K Robert
Ranch Hand

Joined: May 16, 2003
Posts: 116
I have the following:


Origially, this was used to grab the value of a radio button, but I needed to change this to a listbox. Can I use the same code for a <select> if I name the <select> "callerName" and I keep the "value=" attributes the same for the listbox as I did for the radio buttons?

[ December 30, 2005: Message edited by: K Robert ]
[ December 30, 2005: Message edited by: K Robert ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
var sel = forms['CONFIG'].elements['CallerName'];
var strValue = sel.options[sel.selectedIndex].value;
var strText = sel.options[sel.selectedIndex].text;

Eric
K Robert
Ranch Hand

Joined: May 16, 2003
Posts: 116
Great thanks! But, how do I select the right value to display in the listbox base on the variable name?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
loop through the options, read the value, then select when found.



Eric
 
Consider Paul's rocket mass heater.
 
subject: Changing code
 
Similar Threads
Create a Different selectOneListbox Depending On the Radio Button Clicked
text field not populating after validate() fails.
servlets/jsp
Standard Tags, Design Pattern Qs
A formatting question with radio buttons