How Keep state of selected option?

hi all,
    I have a small problem to keep the state of the selected option.

Here  is my code

if  (rs !=null && rs.next())
     {
          do{
               <option value="<%=rs.getInt("id")%><nationality.equalsIgnoreCase(rs.getString("var1"))?"selected":" "%>><%=rs.getString("var1")%></option>
       }while(rs.next());
    }

The problem is the selected option is not selected?
NASEEMAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

boonlengCommented:
Should be as follow:

<option value="<%=rs.getInt("id")%>" <%=nationality.equalsIgnoreCase(rs.getString("var1"))? "selected" : "" %>><%=rs.getString("var1")%></option>
NASEEMAAuthor Commented:
hi,
  I tried the comment but its not working .Where could be the problem.?
boonlengCommented:
Any error encounter?
What is the output (html source) for the above codes?
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

NASEEMAAuthor Commented:
hi,
    No error.The problem is when i select any option its not selected.
The viewsource of the page is

 <select name="nationality">
      <option value="186">Afghanistan</option>
      <option value="221">Albania</option>
      <option value="239">Algeria</option>
      <option value="118">American Samoa</option>
      </select>


The source code of the page is

<option value="<%=rs.getInt("id")%>" <%=nationality.equalsIgnoreCase(rs.getString("var1"))? "selected" : "" %>><%=rs.getString("var1")%></option>
boonlengCommented:
The value of the option are 186, 221...etc
When the page submitted, the value for parameter "nationality" won't equal to the option label.
Try:

    nationality.equalsIgnoreCase(rs.getString("id")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NASEEMAAuthor Commented:
hi,
   Yes you are right .Thanks .

Sorry for the simple mistake -:)
boonlengCommented:
Glad I could help :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.