prain
asked on
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()?.
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()?.
ASKER
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:#000 0CD;font-s ize: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.gen eric_hidde n_button.v alue=param Value; ");
out.println(" document.usereumgrform.sub mit(); ");
out.println("}");
And in then in doPost() I do
//Capture the Generic Hidden Button input.
if (req.getParameter("generic _hidden_bu tton") != null &&
req.getParameter("generic_ hidden_but ton").equa ls("listNa me"))
{
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.
out.println(" <select size =\"1\" name=\"listName\" " +
"onClick=\"submitToDoPost(
" style=width:102;color:#000
......
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.gen
out.println(" document.usereumgrform.sub
out.println("}");
And in then in doPost() I do
//Capture the Generic Hidden Button input.
if (req.getParameter("generic
req.getParameter("generic_
{
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.
ASKER
Sorry I typed wrong...
out.println(" <select size =\"1\" name=\"listName\" " +
"onClick=\"submitToDoPost( this, 'listName')\" " +
" style=width:102;color:#000 0CD;font-s ize:11px > ");
out.println(" <select size =\"1\" name=\"listName\" " +
"onClick=\"submitToDoPost(
" style=width:102;color:#000
what is the HTML on the hidden field?
Just looking at your code again:
>>if (req.getParameter("generic _hidden_bu tton") != null &&
>> req.getParameter("generic_ hidden_but ton").equa ls("listNa me"))
>> {
>> String selectedValue = req.getParameter("listName ");
>> System.out.println("AAAAA : " + selectedValue);
>> }
By doing req.getParameter("generic_ hidden_but ton"), 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
>> req.getParameter("generic_
>> {
>> String selectedValue = req.getParameter("listName
>> System.out.println("AAAAA : " + selectedValue);
>> }
By doing req.getParameter("generic_
Try changing the if statement to:
if (req.getParameter("generic_hidden_button") != null && req.getParameter("generic_hidden_button").length() > 0
ASKER
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:#000 0CD;font-s ize: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.
out.println(" <select size =\"1\" name=\"listName\" " +
"onClick=\"submitToDoPost(
" style=width:102;color:#000
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great. That works. I have another question. I will first close this. please check the same area.
String value = request.getParameter( <param name> );
This should return the value of the option selected in the JSP.