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?
 
ramiseesniblicCommented:
Sorry.

The method on a dropdown list is onChange().

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

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

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

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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 > ");
0
 
ramiseesniblicCommented:
what is the HTML on the hidden field?

0
 
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

0
 
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.
0
 
prainAuthor Commented:
Great. That works. I have another question. I will first close this. please check the same area.
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.