Keep the combobox entries after the form submission
sudheshna Iyer
Ranch Hand
Joined: Aug 20, 2004
Posts: 66
posted
0
I have a form with a combobox and a text box. User selects an entry from the combo box and enters
in the textbox. It is a search functionality. Then System should fetch all the records for selected entry.
The selected entry from combobox and entered text should retain on the screen.
Constant Combo box entries:
Name
Phone
Email
When the user selects an entry and submits the form, selected entry should be sent back to
servlet to fetch the data for the name entered and user should remain on the same screen with
the selected entry (Name here) selected.
How can I keep the user selection (Name as selected here) of combobox after the form submission.
I have a clear button, which should show "none selected". It is not working with the following
JS. This is because I guess the value of selectedColumnName is not cleared.
So my question is, how to access request variables from javascript?
You can't access Java request variables from JavaScript. You can access the form on the page (please show the field declaration rather than the options for this)
When you say after form submission, do you mean an AJAX or regular submit? For AJAX, you shouldn't have to change the values as they would need to be remembered. For a regular submit, the JSP would have to select the desired values.
sudheshna Iyer wrote:I display the selected value as follows:
Do you not think that repeating all the options for every possibility is a bit inefficient and non-maintainable?
Would it not be better to only list the options once, and to determine whether to set the selected attribute on each on individually?
I have a clear button, which should show "none selected". ... So my question is, how to access request variables from javascript?
Why do you need to access the request variables to set the 'none selected' option?
Just set the selected attribute of the desired option and remove it from the others. You're over-engineering the whole thing and making it a lot more complicated than need be.
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
sudheshna Iyer wrote:I display the selected value as follows:
So my question is, how to access request variables from javascript?
To get straight, just let JSP print out those request variables as a Javascript variable.
Regarding to your actual problem. It's a messup. Bear already pointed some important things out.