#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    29
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Belarus
    Posts
    30
    Rep Power
    14
    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%>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    29
    Rep Power
    0
    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

IMN logo majestic logo threadwatch logo seochat tools logo