Link to home
Start Free TrialLog in
Avatar of prain
prainFlag for United States of America

asked on

Capturing Information from multiple List Boxes in the doPost() - How

Ok. Here is the scenario
I have two list boxes. One attach to a submit button and the other attached to another submit button.
All of these are in the same form.
Here is a skeleton of my code.....

 <form method= "post" action="/pSystem/PServlet">
 <table>
 <tr>
  <td>  
    <select name='List1'>;
      <option>item1</option> ");
      <option>item2</option> ");
      <option>item3</option> ");
    </select>
  </td>
  <td>
   <input type="submit\" name=\"from_List1"  value="Select from List 1>
  </td>
 </tr>

 <tr>
  <td>  
    <select name='List2'>;
      <option>item4</option> ");
      <option>item5</option> ");
      <option>item6</option> ");
    </select>
  </td>
  <td>
   <input type="submit\" name=\"from_List2"  value="Select from List 2>
  </td>
 </tr>
 </table>
</form>

Ok. as you see all are in the same form. So when I click, from_list1, it goes
to the  doPost() of PSevlet and also when I click the from_list2, it goes to
the doPost of PSevlet.

What I need to do is when from_list1 is clicked, I want to capture the selected items
in List1 in the doPost() and when I click the from_list2, I want to capture the
selected items in List2.

Any ideas are appreciated.
Avatar of fargo
fargo

use html button instead of submit and use onclick event to change a hidden parameter. So u can set the value of hidden parameter depending upon the button click and submit the form with javascript.

in servlet

if(request.getParameter("hiddenparamname")!=null && request.getParameter("hiddenparamname").equals("hiddenparamValue1")){
listValue= request.getParameter("List1");
}else if(request.getParameter("hiddenparamname")!=null && request.getParameter("hiddenparamname").equals("hiddenparamValue2")){
listValue= request.getParameter("List2");
}



Avatar of prain

ASKER

fargo....

please bear with me...

in your comment, you say "submit the form with javascript"

How to do that?

I am sorry. Not an expert :-)


prain

ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prain

ASKER

fargo,
Ok I got the idea now. Let me get back with you soon with the result.

prain
Avatar of prain

ASKER

Fargo,

That's pretty good. All works well.

Thanks very much.

prain