Solved

how to populate a select box which is dependent on another select box

Posted on 2003-12-03
8
426 Views
Last Modified: 2008-03-10
hi,
i need to populate a select box with values from database. but this should be done based on the value selected in the other select box.

for example,
selectbox1 contains options like:
hardware
software

if hardware is selected, selectbox2 must have the following options(got from the database)
PC
UPS
PRINTERS

could you tell me how to implements it by using action, actionform and jsp

help me regarding this.
0
Comment
Question by:cheungyipyan
8 Comments
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 48 total points
ID: 9865472
Well here is what you will have to do....
First show the form with first select box shown...

<SELECT NAME="SELECTFIELD"  onblur=" submitthis();">
<OPTION VALUE="Hardware">Hardware</OPTION>
<OPTION VALUE="Software">Software</OPTION></SELECT>

<SELECT name="other>
<%
qry=select value from table2 where key=request.getParameter("SELECTFIELD");
rs=stmt.executeQuery(qry);
while (rs.next())
{%>
<OPTION value=<%=rs.getString(1) ><%=rs.getString(1)%.</OPTION>
<%}%>



and submitthis() function will just submit the form back to jsp....
Ofcourse you will have to put some if conditions here and there to control the execution of this query only after submission of the page.. But I am just trying to give a outline here.
Hope this helps


0
 
LVL 14

Assisted Solution

by:kennethxu
kennethxu earned 46 total points
ID: 9867582
0
 

Author Comment

by:cheungyipyan
ID: 9873230
Thank for reply!!
but i need a sample that implements by using Struts
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Assisted Solution

by:u9707118
u9707118 earned 46 total points
ID: 9874071
Check out 'Dependent Drop Down Combo Box Lists' on page 7

http://stealthis.athensgroup.com/presentations/Model_Layer_Framework/Struts_Whitepaper.pdf

Hope this helps,

Damian
0
 

Author Comment

by:cheungyipyan
ID: 9874179
Thank you for all replies
However, i really want to know how to write the codes of JSP, Action and ActionForm to achieve my goal.

Please help me......................
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9874917
It's difficult for us to teach you how to use structs in a forum thread, it's just too much.
I think you much pick up struts yourself, then it is trivial task to translate the given sample to struts with your particular needs.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lamba in java 8 9 252
SimpleDateFormat.parse examples 19 110
iterator example remove 8 75
countXY challenge 28 171
While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question