?
Solved

How to set a form select object with a value?

Posted on 2005-03-24
3
Medium Priority
?
201 Views
Last Modified: 2010-04-01
need to set one of the form options as selected - these options are comming from db an I want to set the option the user prevoius selected with a value i have stored in a string!



%>
                  <select name="countryOptions">
                      <%
                            try
                            {
                        String countryname;
                        while(rs.next())
                                   {
                                    countryname = rs.getString(1);
                              %>
                        <option>
                        <%=countryname%>
                        </option>
                        <%
                                   }
                      }
0
Comment
Question by:climbingjaffa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:arnon81
ID: 13625548
String selected="USA";
%>


<select name="countryOptions">
       <%
              try
              {
                  String countryname;
                  while(rs.next())
                  {
                        countryname = rs.getString(1);
                        if (countryname.trim().equalsIgnoreCase(selected))
                        {
                        %>
                                          
                                          <option SELECTED>
                                                <%=countryname%>
                                          </option>
                        <%
                        else
                        {
                                          <option>
                                                <%=countryname%>
                                          </option>
                        }
                 }
              }
0
 
LVL 2

Accepted Solution

by:
arnon81 earned 1000 total points
ID: 13625567
oops typo..missing parantheses here's the correct one

<%
String selected="USA";
%>


<select name="countryOptions">
       <%
              try
              {
                  String countryname;
                  while(rs.next())
                  {
                        countryname = rs.getString(1);
                        if (countryname.trim().equalsIgnoreCase(selected))
                        {
                        %>
                                          
                                          <option SELECTED>
                                                <%=countryname%>
                                          </option>
                        <%
                        }
                        else
                        {
                                          <option>
                                                <%=countryname%>
                                          </option>
                        }
                 }
              }
0
 
LVL 2

Author Comment

by:climbingjaffa
ID: 13625809
Thanks arnon :-) worked a treat!
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question