Solved

setting a default value for a form field in asp

Posted on 2004-09-07
5
828 Views
Last Modified: 2008-01-09
<%If Not rsCountries.eof then%>              
<select class=content name="COUNTRY" tabindex="14" size="1">
<%If Request.form("country") <> "" Then Do While not rsCountries.Eof
If ucase(Request.form("country")) = ucase(rsCountries("COUNTRY_NAME")) Then%>
<option value="<%=rsCountries("COUNTRY_NAME")%>" selected><%=rsCountries("COUNTRY_NAME")%></option>
<%Else%>
<option value="<%=rsCountries("COUNTRY_NAME")%>"><%=rsCountries("COUNTRY_NAME")%></option>
<%End If
rsCountries.MoveNext
Loop
Else
Do While not rsCountries.Eof%>
<option value="<%=rsCountries("COUNTRY_NAME")%>"><%=rsCountries("COUNTRY_NAME")%></option>
<%rsCountries.MoveNextLoop
End If%>
</select>
<%End If%>
</td>
</tr>
<tr>

Please help !
                                                       
0
Comment
Question by:agodil
5 Comments
 
LVL 3

Expert Comment

by:mattfairw
Comment Utility
please direct comments here so they are all grouped

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21122318.html
0
 
LVL 1

Accepted Solution

by:
mlpk_tyr earned 250 total points
Comment Utility
hi try this,

 <%If  rsCountries.count >0 then%>              
         <select class=content name="COUNTRY" tabindex="14" size="1">
                              <%If Request.form("country") <> "" Then
                                   Do While not rsCountries.Eof
                                           response.writeln("<option value=" & rsCountries("COUNTRY_NAME") )  
                                            <%If ucase(Request.form("country")) = ucase(rsCountries("COUNTRY_NAME")) Then
                                                    response.writeln(" selected ")
                                            <%End If%>
                                            response.writeln(" >" & rsCountries("COUNTRY_NAME") & " </option>" )
                                              <% rsCountries.MoveNext
                                     Loop
                               Else
                                      Do While not rsCountries.Eof%>
                                                 <option value="<%=rsCountries("COUNTRY_NAME")%>"><%=rsCountries("COUNTRY_NAME")%></option>
                                     <%rsCountries.MoveNext
                                        Loop
                              End If%>
              </select>
<%End If%>


hope this work,
mlpk_tyr
0
 

Author Comment

by:agodil
Comment Utility
hey mlpk_tyr, i tried the code you wrote but i does not work ! i get an internal server error! should i post the whole code so you can take a look at it ??
0
 
LVL 19

Expert Comment

by:peh803
Comment Utility
Is this still a problem for you?  Here's some basic code that should work for setting the value of a select box in ASP (I have taken your code and modified it a bit):

<%
If Not rsCountries.eof then
%>
  <select class=content name="COUNTRY" tabindex="14" size="1">
<%
  Do While not rsCountries.Eof
    If ucase(Request.form("country")) = ucase(rsCountries("COUNTRY_NAME")) Then
      sSelected = " selected"
    else
      sSelected = ""
    end if
%>
    <option value="<%=rsCountries("COUNTRY_NAME")%>" <%=sSelected%>>
      <%=rsCountries("COUNTRY_NAME")%>
    </option>
<%
  rsCountries.MoveNext
  Loop
%>
  </select>
<%End If%>
</td>
</tr>

Let me know if this works for you, or if you have any questions.

Regards,
peh803
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now