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

JSP CODE TO SELECT A DROP DOWN LIST ITEM

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hI fRIENDS
i HAVE A PROBLEM WHILE DOING JSP CODING.i HAVE A jSP CODE WHICH CONSISTS OF A DROP DOWN LIST .iF I SELECT A LIST ITEM I SHOULD DISPLAY CORRESPONDING VALUES FROM MYSQL DATABSE IN ANOTHER DROP DOWN lIST
hOW TO SELECT A DROP DOWN lIST ITEM
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,

Have a hidden field in your jsp.
Every time you select an item from the combo ,set the hidden field value to the selected item...
This can be done in a javascript function , for ex.
in a javascript function
selectCombo()
document.formName.hiddenField.value= document.formName.comboBox.value;
now call the servlet from here
document.formName.action=ServletCombo;
document.formName.submit();

Give the function selectCombo() in the onChange() attrirbute of the combo box.
From the servlet you can access the hidden fields value
Using this as the parameter you can execute ur sql command , get the record set , populate a vector or an ArrayList and return to your JSP with the values so as to populate the next combo with these values....

Hope I have not complicated things...
Cheers!
Menon
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator


document.formName.hiddenField.value= document.formName.comboBox.value;
.........
From the servlet you can access the hidden fields value
Using this as the parameter you can execute ur sql command , get the record set .........



Arundhathi,
Pls dont mind my asking, but wouldnt it be a easier soln to get the data from the combo itself.
I mean in the servlet, I can access the value of the comboBox field itself, y assign the value to a hidden field, and then read its value ? Isnt it kinda roundabout ?
I think what she wants is she has a list of 2 items and on selecting one, the other should be displayed. It may mean that she already has the set of data and on clicking one list, the value should be populated in the other. She has already posted this in the jsp forum and I replied to that based on my assumption above.
So Dolly, can u come up with what u require precisely ?
ram.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This forum is for questions about JavaServer Faces so I am going to move this to the JavaServer Pages (JSP) forum.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing this thread, since it is a duplicate of this one. In the future, please do not post questions to multiple forums. Continue discussion of this topic in the other thread.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic