0

Hi I'm a Javascript newbie. I am displaying list of things in my Jsp page. each row has two drop down menus and a radio button. When the submit is clicked it sends the index of the radio button clicked as a hidden parameter. I need to get the drop down menus selected value in the servlet. It seems to be working only for the first item in the table. If i choose the second item and choose something in the drop down menu...when I access it in the servlet it has the first value that is in the drop down no matter what I select.

Please help. I have no clue what the problem is :(

<form  name="cart" method="post" action="listTechnicians" >
  <center>
    <h1>List Books</h1>
      <table border="1" cellpadding="0" cellspacing="0" width="100%" id="bookTable">
           <tr>
             <th align="center" width="15%">Book Id</th>
             <th align="center" width="40%">Initial Title</th>
	    <th align="center" width="15%">Next Task</th>
	    <th align="center" width="15%">New Status </th>
             <th align="center" width="15%">Assign Book</th>
           </tr>
	   <tr>
             <th align="center" width="15%">Curr Status</th>
             <th align="center" width="40%">Title</th>
	    <th align="center" width="15%">Admin</th>
	    <th align="center" width="15%">Galley</th>
	    <th align="center" width="15%">Design</th>
	   </tr>
     <% // java loop 
     int numOfItems = shared.getBooksCount();  
     if (numOfItems >  0)
     {
            String bookid, initialTitle, title, design,galley,admin, status;
            for(int i=0;i<numOfItems;i++) {
               bookid = shared.getListItem(i,0);
       	       initialTitle = shared.getListItem(i,1);
	       title = shared.getListItem(i,2);
	       status = shared.getListItem(i,3);
	       admin  = shared.getListItem(i,4);
	       galley = shared.getListItem(i,5);
 	       design = shared.getListItem(i,6);
       %>
       <tr>
           <td name="id" align='center' valign='center'><%=bookid%></td>
           <td name="initTitle" align='center' valign='center'><%=initialTitle%></td>
	  <td align='center' valign='center'><select name="nextTask">
		<option selected value="scan">Scan</option>
		<option value="galley1">Galley1</option>
	         <option value="galley2">Galley2</option>
	         <option value="galley3">Galley3</option>
		<option value="ISBN">ISBN</option>
		<option value="cover">Cover</option>
	<option value="promotion">Promotion</option></select></td>
	   
   <td align='center' valign='center'><select name="newStatus">
	 <option selected value="assigned">Assigned</option>
	<option value="book">Book</option>
	<option value="taskcomplete">TaskComplete</option>
         <option value="taskproblem">TaskProblem</option>
         <option value="published">Published</option>
         <option value="terminated">Terminated</option></select></td>
           <td name="assign" align="center" valign="center"><input name="book" type="radio"></td>
       </tr>
       <tr>
                <td name="status" align='center' valign='center'><%=status%></td>
	       <td name="title" align='center' valign='center'><%=title%></td>
	       <td name="admin" align='center' valign='center'><%=admin%></td>
	       <td name="galley" align='center' valign='center'><%=galley%></td>
	       <td name="design" align='center' valign='center'><%=design%></td>

       </tr>
       		<%} // end for loop%>
    </table>
</form>

Here is how I am getting the drop down values in the servlet

String nextTask = request.getParameter("nextTask");
        String newStatus = request.getParameter("newStatus");

Edited by Priya123M: n/a

2
Contributors
1
Reply
5
Views
7 Years
Discussion Span
Last Post by javaAddict
0

From what I see you have your select tags inside a for loop?
That would mean that the html generated will have more than one <select> tag.
If you use the request.getParameter, it will always return the first value.
But you send at the request many <select> "items" with name nextTask and newStatus.
So I would suggest to use the method that returns an array of value.

If I remember:

String [] nextTask = request.getParameterValues("nextTask");

I am not sure about the method. Check the API for the method that returns an array of Strings.

Another thing you could do is this:

<input type="hidden" name="numOfItems" value="<%=numOfItems%>" >

<select name="nextTask_<%=i%>">

And:

int numOfItems = Integer.parseInt(request.getParameter("numOfItems "));
for (int i=0;i<numOfItems ;i++) {
  String nextTask = request.getParameter("nextTask_"+i);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.