I'm trying to save and retrieve status for a submitted form on a JSP. Retrieving textbox answers is relatively simple but for selection boxes I'm doing this:
<%String countryDB = rs.getString("countryDB"); %> //get value last submitted
<td valign="TOP" height="21" colspan="3"> //now try and re-select it.
<select name="country" >
<option value="" >Pull down to select
<option value="Afghanistan" <%if (country.equals("Afghanistan")) {%> selected <%} %>>Afghanistan</option>
<option value="Albania" <%if (country.equals("Albania")) {%> selected <%} %>>Albania</option>
<option value="Algeria"<%if (country.equals("Algeria")) {%> selected <%} %>>Algeria</option>
...etc...etc
</td>
I'm trying to compare the value I have in the database with the value for each of the select values.
Is there an easier way to write this without having to add and change the "<%if (country.equals("selectValue")) {%> selected <%} %>" for each of the hundred countries .
You could probably do it using javaScript with the onLoad function to cycle through the values of the form, but I'm not sure what the best way to go about this is.
<%String countryDB = rs.getString("countryDB"); %> //get value last submitted
<td valign="TOP" height="21" colspan="3"> //now try and re-select it.
<select name="country" >
<option value="" >Pull down to select
<option value="Afghanistan" <%if (country.equals("Afghanistan")) {%> selected <%} %>>Afghanistan</option>
<option value="Albania" <%if (country.equals("Albania")) {%> selected <%} %>>Albania</option>
<option value="Algeria"<%if (country.equals("Algeria")) {%> selected <%} %>>Algeria</option>
...etc...etc
</td>
I'm trying to compare the value I have in the database with the value for each of the select values.
Is there an easier way to write this without having to add and change the "<%if (country.equals("selectValue")) {%> selected <%} %>" for each of the hundred countries .
You could probably do it using javaScript with the onLoad function to cycle through the values of the form, but I'm not sure what the best way to go about this is.