Link to home
Start Free TrialLog in
Avatar of acslater
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></td>
                                <td colspan=3 align="left" valign="bottom">
                                  <select name="County">
                                    <OPTION value= "County" Selected>County</OPTION>




                                   <option value="Carlow">Carlow</option>
                                    <option value="Cavan">Cavan</option>
                                    <option value="Clare">Clare</option>
                                    <option value="Cork">Cork</option>
                                    <option value="Donegal">Donegal</option>
                                    <option value="Dublin">Dublin</option>
                                    <option value="Galway">Galway</option>
                                    <option value="Kerry">Kerry</option>
                                    <option value="Kildare">Kildare</option>
                                    <option value="Kilkenny">Kilkenny</option>
                                    <option value="Laois">Laois</option>
                                    <option value="Leitrim">Leitrim</option>
                                    <option value="Limerick">Limerick</option>
                                    <option value="Longford">Longford</option>
                                    <option value="Louth">Louth</option>
                                    <option value="Mayo">Mayo</option>
                                    <option value="Meath">Meath</option>
                                    <option value="Monaghan">Monaghan</option>
                                    <option value="Offaly">Offaly</option>
                                    <option value="Roscommon">Roscommon</option>
                                    <option value="Sligo">Sligo</option>
                                    <option value="Tipperary">Tipperary</option>
                                    <option value="Waterford">Waterford</option>
                                    <option value="Westmeath">Westmeath</option>
                                    <option value="Wexford">Wexford</option>
                                    <option value="Wicklow">Wicklow</option>
                                    <option>None of the Above</option>
                                  </select>
                                </td>
                              </tr>

Avatar of acslater
acslater

ASKER

any replys Tim i know you can help!!!
ASKER CERTIFIED SOLUTION
Avatar of orhanbaba
orhanbaba

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry it will be  last line
for example
      <select name="County">
                                    <OPTION value= "County" Selected>County</OPTION>//selected
      <option value="Carlow">Carlow</option>
                                    <option value="Cavan">Cavan</option>
                                    <option value="Clare">Clare</option>
                                    <option value="Cork">Cork</option>
                                    <option value="Donegal">Donegal</option>
<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
Avatar of TimYates
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 :-)
Its ok the first one works and its only one line of code

<OPTION selected ><%=rs21.getString ("Town")%></OPTION>