Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am building my first JSP interface and I have successfully interrogated a SQL Server database to populate a dropdown list box and then using JQuery to take the selected value from the list box and place it in a text box. How do I know use the selected value to build a SQL statement to populate a second list box? Basically the value chosen by the first list box filters the values dispalyed in the second list box.

I have used the taglib directives to build my initial SQL query.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

Then assigned its results to the first list box;

XML
<Select name="UserID" id="UserIDs" class="seluserval">
      <c:forEach items="${result.rows}" var="st">
            <option value="1"><c:out value="${st.USER_ID}"/></option>
      </c:forEach>
      </select>


Then used the following JQuery to place the selected value in the text box;

C#
var main = function() {
    $('#UserIDs').on('change',function(){
    var selUser = $('#UserIDs :selected').text();
    $('#selecteduservalue').val(selUser);
});
};

$(document).ready(main);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900