开发者

jQuery to create dynamic drop down list

I am currently using jsp and I wanted to create a dynamic drop down list. When the page first loads I have this drop down list:

<select name="target" id="target">
    <option value="">--Select an option--</option>
    <option value="add">Add a client with a program</option>
    <option value="exit">Mark a client as exit client</option>
    <option value="refuse">Refuse a client</option>
</select>

If on a user changes the value of the drop down and the value is add then I would like to execute the following query in my jsp page:

 String query = "SELECT * FROM CLIENT ORDER BY CID DESC";

 ResultSet result = s.executeQuery(query);

 while(result.next()) {
    out.print("<option value=" + result.getString("CID") + ">");
    out.print(result.getString("Name") + " (" + result.getString("CID")+")");
    out.print("</option>\n");                   
} 

if the user choose's exit then a different qu开发者_StackOverflow中文版ery is executed, how can I do this? Basically what I want from the jQuery perspective is so it can change the query value on an onChange event on the select option and run executeQuery


Place your Java script in a different page assume request_handler.jsp and Use JQUERY AJAX method to send request to that page and return a new page with fresh tags and their values. Then use something like $("target").html(new_html) to replace the old values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜