0

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 query 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

aherlambang
  • 14,290
  • 50
  • 150
  • 253
  • This has what, exactly, to do with jQuery? You should also be using JSTL if possible. – Matt Ball Dec 04 '10 at 16:46
  • Please rephrase your question, it's kind of unclear what you want to achieve and what's the problem here. – Kos Dec 04 '10 at 16:48
  • I thought I need some jQuery code to query the database or trigger a specific jsp.. I revised the question, hope it's a bit clear now – aherlambang Dec 04 '10 at 16:58
  • 1
    possible duplicate of [Populating child dropdownlists in JSP/Servlet](http://stackoverflow.com/questions/2263996/populating-child-dropdownlists-in-jsp-servlet) (see way 3) – BalusC Dec 04 '10 at 18:05

1 Answers1

0

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.

Sailab Rahi
  • 581
  • 1
  • 8
  • 11