Solved

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

Posted on 2003-12-03
8
425 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reflection example 3 110
problem with  angularjs dropdwon search at object property (name) level 2 104
struts exact match support 3 57
jsp error 6 25
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This article describes how to reset your Windows 10 password when you've forgotten it.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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