| Author |
Getting value of a select element
|
Beth Candida
Greenhorn
Joined: Apr 26, 2012
Posts: 4
|
|
Hi!
I have a form, which displays different drop down boxes based on the radio button selected. On SUBMIT button, I validate whether a radio button is pressed or not.
The above requirement is wrking fine. Now on successful validation i.e. on click of "SUBMIT" button, I want to display the value selected from the drop down as an alert.
I am unable to do so cause I am not sure how will i pass the selected drop down value on click of submit button.
Say for example: I select "California" on selecting radio button "USA"...hw wud i pass the value nd display "California" as an alert?
Its a lilltle urgent! Would really appreciate any help!! Thanks in advance!
My code:
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Since your issue is with JavaScript, not JSP, you need to debug this on the client.
Be sure that the JavaScript console for your browser is open so you can see any errors that are occurring. At what point does code go wrong? What part works and what part does not?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Beth Candida
Greenhorn
Joined: Apr 26, 2012
Posts: 4
|
|
Thanks Bear Bibeault! amazing that you formatted the code for me..looks indeed understandable.
Can some help provide me with a solution to my query? I want to display the value selected by the dropdown onclick of "SUBMIT" button.
|
 |
Nikhil Padharia
Ranch Hand
Joined: Apr 19, 2012
Posts: 37
|
|
You will need to store the value of the select-box shown in a globally declared javascript variable.
And using that id retrieve the value of combo value selected using
Hope this helps.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Nikhil Padharia wrote:You will need to store the value of the select-box shown in a globally declared javascript variable.
Not so. In fact, globals should be avoided unless absolutely necessary.
The value can be obtained in the submit handler whiteout needing to store it anywhere.
|
 |
Beth Candida
Greenhorn
Joined: Apr 26, 2012
Posts: 4
|
|
|
thanks!but still i am unable to understand the solution..my drop down elelmnet IDs are diffferent in each case..as in it depends on the radio button selected..How do i go abt it?
|
 |
 |
|
|
subject: Getting value of a select element
|
|
|