Solved

setting a default value for a form field in asp

Posted on 2004-09-07
5
862 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
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 250 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

809 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