• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting value of a select element

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic