This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Getting value of a select element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Getting value of a select element" Watch "Getting value of a select element" New topic
Author

Getting value of a select element

Beth Candida
Greenhorn

Joined: Apr 26, 2012
Posts: 18
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: 61451
    
  67

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Beth Candida
Greenhorn

Joined: Apr 26, 2012
Posts: 18
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: 61451
    
  67

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: 18
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting value of a select element