?
Solved

setting a default value for a form field in asp

Posted on 2004-09-07
5
Medium Priority
?
889 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
[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
5 Comments
 
LVL 3

Expert Comment

by:mattfairw
ID: 12002227
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 750 total points
ID: 12003916
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
ID: 12010392
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
ID: 12030527
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

762 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