Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-05
5
Medium Priority
?
188 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:prain
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 16384901
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
 

Author Comment

by:prain
ID: 16385084
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
 
LVL 11

Accepted Solution

by:
fargo earned 500 total points
ID: 16385141
<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
 

Author Comment

by:prain
ID: 16385193
fargo,
Ok I got the idea now. Let me get back with you soon with the result.

prain
0
 

Author Comment

by:prain
ID: 16391619
Fargo,

That's pretty good. All works well.

Thanks very much.

prain
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What happened when I tried to make my phone, a Samsung Galaxy S8, stop dropping all WiFi signals was a saga I won't repeat here, but what you might want to know is how it started and how I got it working again.
Are you a startup company? Being a startup, you may be using shared hosting, or maybe even dedicated hosting. But have you ever given a thought to using cloud computing now? Yes, don’t be surprised, it is possible for startups to opt for cloud compu…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question