#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    16
    Rep Power
    0

    Unhappy Help! How to get multiple values from a listbox?


    I used the following code to create a listbox:

    <%String sql = "select distinct year from yearTable order by year";
    rs = stmt.executeQuery(sql);%>

    Year: <select size="3" name="year" MULTIPLE>
    <option>Select a year</option>
    <%while(rs.next()) {
    if(rs.getString(1)!=null && rs.getString(1).length() > 0){%>
    <option><%= rs.getString(1)%></option>
    <%}
    }%>


    Then I need to submit a query to MySQL according to all the selected items in the listbox.

    Can anyone tell me how to get all the values?
    request.getParameter("year") only get the first item selected.

    Thanks a lot.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    5
    Rep Power
    0
    getParameterValues() returns an array of all the values with the named parameter so

    String[] years = req.getParameterValues("year");

    will give you an array of all the "year" parameters.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    16
    Rep Power
    0

    Cool Thank you very much, Nicholas!


    Thanks a lot. I had been searching for an answer in an online
    book but didn't get it. Thanks a lot.

IMN logo majestic logo threadwatch logo seochat tools logo