KirbyD
KirbyD

Reputation: 51

dynamic dependent select box in jsp HELP pls

i need some help on how to use jquery ajax in my jsp , there is so many example in the web but it is base on php and some doesnt have sql involve.

I have 2 select box in my jsp

<tr><td>Category</td>   
    <td><select  name="category">
    <c:forEach var="c" items="${cList}">
        <option value="${c.cname}"}>${c.cname}</option>
    </c:forEach></td>
</select></tr>
    <tr><td>Brand</td>  
    <td><select  name="brand">
    <c:forEach var="b" items="${bList}">
        <option value="${b.bname}"}>${b.bname}</option>
    </c:forEach></td>
</select></tr>


    <script type="text/javascript">
$(document).ready(function(){
        $("select[name=category]").on("change", function(){
              $("select[name=brand] option")
                .hide().removeAttr("selected")
                .parent().find("option[value^="+ $(this).val() +"]").show()
                .first().prop("selected",true);
            });

});


</script>

ANd i want the BRAND select box is dependent on the Category. For ea. When i choose a category it will list all the brands available? huhuhuhuhu help me pls no knowledge about jquery-ajax.

How can i achieve this example using jsp with controllers and dao

http://demo.coffeecupweb.com/dddd/

Upvotes: 0

Views: 781

Answers (1)

user3386779
user3386779

Reputation: 7215

Try the sample code in the link demo This sample is for

  <h3>AJAX in Servlet using JQuery and JSON</h3>
    Select Favorite Sports:
    <select id="sports">
            <option>Select Sports</option>
            <option value="Football">Football</option>
            <option value="Cricket">Cricket</option>
    </select>
    <br /> <br /> 
    Select Favorite Player:
    <select id="player">
            <option>Select Player</option>
    </select>

Upvotes: 1

Related Questions