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.
prainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
fargoCommented:
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");
}



0
 
prainAuthor Commented:
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

0
 
fargoCommented:
<html>
<head>
<script>
     function updateAndSubmit(paramValue){
        document.formname.list_button_name.value=paramValue;
       document.formname.submit();
     }
</script>
</head>
<body>

<form name="formname" method="post" action="...">
<input type="hidden" name="list_button_name"/>
...
...
<input type="button" name="list_button_1" onclick="updateAndSubmit('list_button_1')"/>
....
....
<input type="button" name="list_button_2" onclick="updateAndSubmit('list_button_2')"/>
</form>

0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
prainAuthor Commented:
fargo,
Ok I got the idea now. Let me get back with you soon with the result.

prain
0
 
prainAuthor Commented:
Fargo,

That's pretty good. All works well.

Thanks very much.

prain
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.