acslater
asked on
selecting data from the database with drop down list for update
Hi there i asked this question already but left it alone gone back to fix it now and the stuff i was told to try isnt working i have 2 pages a change.jsp and changed.jsp
In change i have text boxes and drop down boxes containing member information i have the information coming from the database inserting into the text boxes, but i also have drop down boxes and when the user clicks on the page to update their details i want the drop down box already selected with their details here is some code:
-------------------------- ---------- ---------
<tr>
<td align="right" valign="bottom" bgcolor="#ffffff" class="subtitle"><div align="left"><b>Town:</b>< /div></td>
<td colspan=3 align="left" valign="bottom">
<input name="Town" size="35" maxlength="25" tabindex="10" value="<%=rs21.getString ("Town")%>">
-------------------------- ---------- ---------- ---------- ---
This is how im doing it for the text box
-------------------------- ---------- ---------- ---------- --------
this is the code for the drop down box
</td>
</tr>
<tr>
<td align="right" valign="bottom" bgcolor="#ffffff" class="subtitle"><div align="left"><b>County:</b ></div></t d>
<td colspan=3 align="left" valign="bottom">
<select name="County">
<OPTION value= "County" Selected>County</OPTION>
<option value="Carlow">Carlow</opt ion>
<option value="Cavan">Cavan</optio n>
<option value="Clare">Clare</optio n>
<option value="Cork">Cork</option>
<option value="Donegal">Donegal</o ption>
<option value="Dublin">Dublin</opt ion>
<option value="Galway">Galway</opt ion>
<option value="Kerry">Kerry</optio n>
<option value="Kildare">Kildare</o ption>
<option value="Kilkenny">Kilkenny< /option>
<option value="Laois">Laois</optio n>
<option value="Leitrim">Leitrim</o ption>
<option value="Limerick">Limerick< /option>
<option value="Longford">Longford< /option>
<option value="Louth">Louth</optio n>
<option value="Mayo">Mayo</option>
<option value="Meath">Meath</optio n>
<option value="Monaghan">Monaghan< /option>
<option value="Offaly">Offaly</opt ion>
<option value="Roscommon">Roscommo n</option>
<option value="Sligo">Sligo</optio n>
<option value="Tipperary">Tipperar y</option>
<option value="Waterford">Waterfor d</option>
<option value="Westmeath">Westmeat h</option>
<option value="Wexford">Wexford</o ption>
<option value="Wicklow">Wicklow</o ption>
<option>None of the Above</option>
</select>
</td>
</tr>
In change i have text boxes and drop down boxes containing member information i have the information coming from the database inserting into the text boxes, but i also have drop down boxes and when the user clicks on the page to update their details i want the drop down box already selected with their details here is some code:
--------------------------
<tr>
<td align="right" valign="bottom" bgcolor="#ffffff" class="subtitle"><div align="left"><b>Town:</b><
<td colspan=3 align="left" valign="bottom">
<input name="Town" size="35" maxlength="25" tabindex="10" value="<%=rs21.getString ("Town")%>">
--------------------------
This is how im doing it for the text box
--------------------------
this is the code for the drop down box
</td>
</tr>
<tr>
<td align="right" valign="bottom" bgcolor="#ffffff" class="subtitle"><div align="left"><b>County:</b
<td colspan=3 align="left" valign="bottom">
<select name="County">
<OPTION value= "County" Selected>County</OPTION>
<option value="Carlow">Carlow</opt
<option value="Cavan">Cavan</optio
<option value="Clare">Clare</optio
<option value="Cork">Cork</option>
<option value="Donegal">Donegal</o
<option value="Dublin">Dublin</opt
<option value="Galway">Galway</opt
<option value="Kerry">Kerry</optio
<option value="Kildare">Kildare</o
<option value="Kilkenny">Kilkenny<
<option value="Laois">Laois</optio
<option value="Leitrim">Leitrim</o
<option value="Limerick">Limerick<
<option value="Longford">Longford<
<option value="Louth">Louth</optio
<option value="Mayo">Mayo</option>
<option value="Meath">Meath</optio
<option value="Monaghan">Monaghan<
<option value="Offaly">Offaly</opt
<option value="Roscommon">Roscommo
<option value="Sligo">Sligo</optio
<option value="Tipperary">Tipperar
<option value="Waterford">Waterfor
<option value="Westmeath">Westmeat
<option value="Wexford">Wexford</o
<option value="Wicklow">Wicklow</o
<option>None of the Above</option>
</select>
</td>
</tr>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry it will be last line
for example
<select name="County">
<OPTION value= "County" Selected>County</OPTION>// selected
<option value="Carlow">Carlow</opt ion>
<option value="Cavan">Cavan</optio n>
<option value="Clare">Clare</optio n>
<option value="Cork">Cork</option>
<option value="Donegal">Donegal</o ption>
<OPTION selected ><%=rs21.getString ("Town")%></OPTION> //it will be selected
<option>None of the Above</option>
</select>
both variable has selected value but last one will be shown
<select name="County">
<OPTION value= "County" Selected>County</OPTION>//
<option value="Carlow">Carlow</opt
<option value="Cavan">Cavan</optio
<option value="Clare">Clare</optio
<option value="Cork">Cork</option>
<option value="Donegal">Donegal</o
<OPTION selected ><%=rs21.getString ("Town")%></OPTION> //it will be selected
<option>None of the Above</option>
</select>
both variable has selected value but last one will be shown
I thought we already covered this in: https://www.experts-exchange.com/questions/21371125/Selecting-data-from-the-database-with-drop-down-list-for-update.html
--------------
If you store all the counties as Strings in an array:
<%
String[] countyArray = { "County", "Carlow", "Cavan", ...etc..., "Wicklow" } ;
%>
then, you should be able to do:
<% String county = rs21.getString( "County" ) ; %>
<select name="County">
<% for( int i = 0 ; i < countyArray.length ; i++ ) {
<OPTION value= "<%= countyArray[ i ] %>" <%= county != null && county.equals( countyArray[ i ] ) ? "SELECTED" : "" %>><%= countyArray[ i ] %></OPTION>
<% } %>
<option <%= county == null ? "SELECTED" : "" %>>None of the Above</option>
</select>
which is neater :-)
--------------
If you store all the counties as Strings in an array:
<%
String[] countyArray = { "County", "Carlow", "Cavan", ...etc..., "Wicklow" } ;
%>
then, you should be able to do:
<% String county = rs21.getString( "County" ) ; %>
<select name="County">
<% for( int i = 0 ; i < countyArray.length ; i++ ) {
<OPTION value= "<%= countyArray[ i ] %>" <%= county != null && county.equals( countyArray[ i ] ) ? "SELECTED" : "" %>><%= countyArray[ i ] %></OPTION>
<% } %>
<option <%= county == null ? "SELECTED" : "" %>>None of the Above</option>
</select>
which is neater :-)
ASKER
Its ok the first one works and its only one line of code
<OPTION selected ><%=rs21.getString ("Town")%></OPTION>
<OPTION selected ><%=rs21.getString ("Town")%></OPTION>
ASKER