Want to capture the selected item from a list immediately after the click, in doPost()

Hello.
I am writing a Servlet. I have a JComboBox style drop down list box. I click an Item, I want to capture the selected item and then show this in a textfield. How do I capture the selected item from the list immediately in teh doPost()?.
prainAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

ramiseesniblicCommented:
In the doPost() method, you should be able to do:

String value = request.getParameter( <param name> );

This should return the value of the option selected in the JSP.

prainAuthor Commented:
It does not. That's the problem I have. Here is the script I create the list.

 out.println("    <select  size =\"1\" name=\"listName\" " +
               "onClick=\"submitToDoPost(this, 'listNme')\" " +
               " style=width:102;color:#0000CD;font-size:11px > ");
......
The I have code to add items into the list. That's dicplayed nicely.

 Where the submitToDoPost() function is scripted like this......

 out.println("<html> ");
   out.println("<SCRIPT type=\"text/javascript\"> ");
   out.println("");
   out.println("function submitToDoPost(theBtn, paramValue)");
   out.println("{");
   out.println("   document.usereumgrform.generic_hidden_button.value=paramValue; ");
   out.println("   document.usereumgrform.submit(); ");
   out.println("}");

And in then in doPost() I do
//Capture the Generic Hidden Button input.
  if (req.getParameter("generic_hidden_button") != null && 
       req.getParameter("generic_hidden_button").equals("listName"))
  {
    String selectedValue  =  req.getParameter("listName");

    System.out.println("AAAAA : " +  selectedValue);
  }

This print statement is not being printed. I feel that the message is not sent to doPost() when the list item is clicked.

prainAuthor Commented:
Sorry I typed wrong...

out.println("    <select  size =\"1\" name=\"listName\" " +
               "onClick=\"submitToDoPost(this, 'listName')\" " +
               " style=width:102;color:#0000CD;font-size:11px > ");
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

ramiseesniblicCommented:
what is the HTML on the hidden field?

ramiseesniblicCommented:
Just looking at your code again:

>>if (req.getParameter("generic_hidden_button") != null && 
>>       req.getParameter("generic_hidden_button").equals("listName"))
>>  {
>>    String selectedValue  =  req.getParameter("listName");
>>    System.out.println("AAAAA : " +  selectedValue);
>>  }

By doing req.getParameter("generic_hidden_button"), you are getting the value of the hidden field that has been submitted, and then checking that it equals "listName".

Try changing the if statement to:

if (req.getParameter("generic_hidden_button") != null && req.getParameter("generic_hidden_button").length() > 0

Open in new window

prainAuthor Commented:
First of all, should onClick   the correct way of doing this into a dropdown list box?. This is correct I know to a Push Button. Why I am saying is that because when I have my drop down listbox (combobox) created like this :
out.println("    <select  size =\"1\" name=\"listName\" " +
               "onClick=\"submitToDoPost(this, 'listName')\" " +
               " style=width:102;color:#0000CD;font-size:11px > ");

It does not allow me to click an "Item" in the drop. In fact it does not allow me to select drom the drop. The moment the drop down thumb is clicked it calls doPopst(). So I think for a dropdown listbox, onClik may not be the corect form.
ramiseesniblicCommented:
Sorry.

The method on a dropdown list is onChange().

That get's called when the value of the select is changed.

Experts Exchange Solution brought to you by

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:
Great. That works. I have another question. I will first close this. please check the same area.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.