Solved

setting a default value for a form field in asp

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
PHP email variable syntax 3 53
css border raidius issue 7 97
Field that has HTML displays the code instead of the text in html 16 122
Problem to page 4 103
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 …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 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