Solved

setting a default value for a form field in asp

Posted on 2004-09-07
5
853 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Clean URL from GET variables 2 101
Forbidden errors 5 143
Advice on what platform to use for a web app for AWS 3 98
Questions about this React unit test 4 63
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

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