• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting value of a select element

 
Beth Candida
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Beth Candida
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic