• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

Urgent: Getting state of drop down box

I have a form that brings up all the members details in text fields they all come up except for the drop down box gender which still shows select.... when it should show M or F for the selected memeber. HERE is code i have now:

<td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Local Doctor</strong></td>
                        <td width="83%"><input name="PatientLocalDoctor" type="text" id="PatientLocal" value="<%=rs.getString("PatientLocalDoctor")%>"></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <table width="85%" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666">
                <tr>
                  <td bgcolor="E3EDFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="17%"><strong>Gender</strong></td>
                        <td width="83%"><Select name="PatientGender" id="PatientGender" value="<%=rs.getString("PatientGender")%>">
                                    
                                    <option>Select...</option>
                                    <option value="F">F</option>
                                    <option value="M">M</option>
                                    </select>
                                    </td>
                      </tr>
                    </table></td>
                </tr>
              </table>
The gender one is not showing the value, it just shows select....
0
act1ve
Asked:
act1ve
  • 4
  • 2
2 Solutions
 
objectsCommented:
you need to "selected" to the option you want selected
something like:

<option value="F" <%= sex=='F' ? "selected" : "" %> >F</option>
<option value="M" <%= sex=='M' ? "selected" : "" %> >M</option>
0
 
bloodredsunCommented:
it doesn't work like that, you need this:

<select name="PatientGender" id="PatientGender">
<option>Select...</option>
<%
String selected = rs.getString("PatientGender") ;

if ( "M".equals( selected ) ){
     out.println("<option selected>M</option>");
}else{
     out.println("<option>M</option>");
}
if ( "F".equals( selected ) ){
     out.println("<option selected>F</option>");
}else{
     out.println("<option>F</option>");
}
%>
</select>
0
 
bloodredsunCommented:
Can you use ""==<char> on Strings, objects?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
bloodredsunCommented:
By the way, " it doesn't work like that, you need this:" was refering to the question, not your code! :-)
0
 
objectsCommented:
> Can you use ""==<char> on Strings, objects?

No, I was using it on char's (assuming that a char var sex existed that held the sex to be selected)

char sex = rs.getString("PatientGender").charAt(0);

0
 
bloodredsunCommented:
Thought so...and the ternary operator makes it much easier to read IMHO, I only used if/else for emphasis and I thought it would be easier for act1ve one to understand....
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now