This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

JSP CODE TO SELECT A DROP DOWN LIST ITEM

 
DOLLY REDDY
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Arundhathi Menon
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • 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
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic