Solved

Use 2 combo boxes to correspond with eachother

Posted on 2004-09-15
4
286 Views
Last Modified: 2010-04-01
I need 2 combo boxes to correspond with eachother on my JSP page. If a user picks a selection from "combobox1" I want my SQL query that is embedded in a "DataHandler" class file to use that value to populate "combobox2" which is in the same JSP page.

this is what I have in my JSP page so far.....

I've set up a combo box for one of them to show where everything is coming from, and the format to kind of follow.

What I want it to do is when the first combo box changes, I want the second (new) combo box to populate, according to what the value (getuserid()) is in the first combo box.......

<html>
<head>
    <title>EmailCombo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
        <!--
        function MM_openBrWindow(theURL,winName,features) { //v2.0
        window.open(theURL,winName,features);
        }
        //-->
    </script>
</head>

<body>
    <font size="4" face="Arial, Helvetica, sans-serif"></strong>
    <div align=center>Deliverable Evaluation Form: Document </div>
    <font size="2">
    <p>&nbsp;</p>
    <hr size="5" align="center" noshade>
    <strong>Section 1: Agency and Task Information</strong>
        <%@page import="bah.arl.util.*" %>
        <%@page import="bah.arl.evaluations.*" %>
        <%@page import="bah.arl.evaluations.servlet.*" %>
        <%@page import="java.util.*" %>
        <%@page import="java.sql.*" %>
<%
try
{
Properties props = new Properties();

//DataHandler class connects to my database//
DataHandler dataHandler =  new DataHandler(getServletContext().getInitParameter("abc"), getServletContext().getInitParameter("dbName"), "user1", "user1");

//This ArrayList is set up as a query in my DataHandler class... SELECT * FROM USERS
ArrayList emails = dataHandler.getAllUserids();

//This is actually a servlet "evaluationsSessionBean that sets Userids...
evaluationsSessionBean evaluationsSessionBean = new evaluationsSessionBean();
evaluationsSessionBean.setUserids(emails);

session.setAttribute("evaluationsSession", evaluationsSessionBean);

%>
       <form name="reqForm" method="post" action="http://localhost:8080/evaluations/evaluations.jsp?requestType=1" target="docEvaluation.jsp">
        <p>
        <table border="0" width="25%">
        <tr><td><font size="2">Choose Your Agency:</font></td>
        <td>
  <select name="agencyID">
        </p>
    <%
        Iterator emailsIter = emails.iterator();
        while(emailsIter.hasNext())
        {
            UserIDs currUser = (UserIDs)emailsIter.next();
       
    %>
            <option value="<%=currUser.getuserid()%>"><%=currUser.getuserid()%></option>
    <%
        }
    %>
        </select></td></tr>
     
   <%
 }
 catch(Exception err)
 {
    err.printStackTrace();
    out.println("what\n");
 }
        %>
        </tr></table>
       <p>&nbsp;</p>
        <p>&nbsp;</p>
       
        <input type="submit" name="systemButton" value="Submit">
        <input type="reset" name="clearForm" value="Reset">
        </p>
        </form>
        &nbsp;
    </font>
</body>
</html>
0
Comment
Question by:apapanic
  • 2
4 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12068807
Is this the same question as http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21123826.html

Javascript is the easiest way to do this...  But you should really sort out the first question before asking the same thing again...
0
 

Author Comment

by:apapanic
ID: 12071530
It is similar, can you answer the first question?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12073094
You will have to use javascript at some level for doing this...

either like suggested in the other question, or by adding a onChange event to the 1st combobox so that it posts the form to the server again, which can set the values for the second combo box.

you can add a hidden field to the form, which a javascript method can set to "populate" when the combobox is changed and then the server can get this field, and if it has the value "populate", it can fil in the second combo box dependant on the value of the first one, and send this new HTML page to the user.

But that is the only way I can think of doing it that will work across multiple browsers...

Tim
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 12091432
Something like this:
<form name='reqForm' action='' method='get>
   ...
   <select name='agencyID' onchange='reqForm.submit()'>
     <%...Code to populate this list...%>
   </select>
   ...
   <select name='depenantList'>
      <%...Code to populate this list OR empty list if agencyID is not selected...%>
   </select>

    <input type='submit' name='systemButton'
value='Submit' onclick='javascript:reqForm.action='http://localhost:8080/evaluations/evaluations.jsp?requestType=1';reqForm.target='docEvaluation.jsp';return true;'/>
...
</form>

This page will submit the form when the user changes the 1st droplist.  The 2nd droplist will be empty because the 1st droplist has no default choice selected.  The action is '' so the page will be submitted back to the same page.  The second page will populate the 1st and seconds droplists again, but this time the second droplist will use the 1st droplist as a key to queryt the DB and populate the 2nd droplist.  When the user clicks the submit button the javascript changes the action to the new page and the form is submitted to the other page.

NOTE: the Onclick for the submit button should probably be moved to a javascript function so you can do validation as well.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export JSON response data to Excel in IE9 3 67
How to Post an If Statement in JSP 3 51
maven j2ee examles 2 49
Market Place not working in Eclipse Luna 2 101
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now