|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can't compare strings
I'm trying to compare strings in a select statement. It's part of an edit function that selects a records and loads the results in a form. The select box that lists the locations does not work. I'm feeding all the right information as I've echoed out the values but I can't get a match. The location in the list box always 'checks' the last one take from the db. My code is:
<select name="jobLocation" class="dropdown"> <option value="" checked>Select a Location <% String locQuery = "SELECT locID, jobLocation from tblHRLocations"; // get result ResultSet SQLLocationResult = SQLStatement.executeQuery(locQuery); while(SQLLocationResult.next()) { jobLocation = SQLLocationResult.getString("jobLocation"); jobLocation = jobLocation.trim(); %> <option value="<%out.println(jobLocation);%>" <%if(jobLocationSelected.equals(jobLocation));{%>selected<%}%>><%out.println(jobLocation);%> <% } %> </select> Can anyone tell me what I'm doing wrong? This is a real showstopper right now and I really need some help. Thanks. Bob |
|
#2
|
|||
|
|||
|
hi 43rdworld
this world is 43rd for you? you made some little mistake here Code:
<option value="<%out.println(jobLocation);%>" <%if(jobLocationSelected.equals(jobLocation)); {%>selected<%}%><%out.println(jobLocation);%>
better way to write this Code:
<option value="<%=jobLocation%>" <%=jobLocationSelected.equals(jobLocation) ? "SELECTED" : "" %> ><%=jobLocation%> |
|
#3
|
|||
|
|||
|
Well, so far the world is the only one but I think this is my 43rd ID on these forums as I keep forgetting the previous one. Actually, it's for 1/43 scale models and the web site I'm developing.
Thanks for the answer. I've never seen that particular format in any of the books I've read but am extremely glad for the answer! Much appreciated! Bob |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Can't compare strings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|