File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP CODE TO SELECT A DROP DOWN LIST ITEM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

JSP CODE TO SELECT A DROP DOWN LIST ITEM

DOLLY REDDY
Greenhorn

Joined: Feb 08, 2005
Posts: 7
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

Joined: Jan 14, 2004
Posts: 113
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


SCJP , SCWCD , SCBCD , SCDJWS
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


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

Joined: Jul 11, 2001
Posts: 15299
    
    6

This forum is for questions about JavaServer Faces so I am going to move this to the JavaServer Pages (JSP) forum.


GenRocket - Experts at Building Test Data
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP CODE TO SELECT A DROP DOWN LIST ITEM