Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 5th, 2006, 05:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default option selected from a select box

Hello

I'm using asp & mssql server and inputting data into the db via a select box (this is in a content management system). However, when I go to edit the item I want the select box to display the data that I initially put into the select box and then follow on with the rest of the info from the select box. Here's my code for the edit page:

<%

            if isNull(strArtist) or (strArtist) = Empty then

set con = server.createobject("ADODB.Connection")
con.open Application("MyString")

strSQL2 = "SELECT * FROM tbl_artists ORDER BY Artist ASC"
Set rsArtist = con.execute(strSQL2)

%>
              <select name="txtArtist" class="TextBox_X" id="txtArtist">
                <%
if Request("Artist") = empty then
%>
                <option value="" selected>-- Select Artist --</option>
                <%
end if

do while not rsArtist.EOF

    if CStr(request("ArtistID")) = Cstr(rsArtist("Artist")) then
%>
                <option value="<%=rsArtist("ArtistID")%>" selected><%=rsArtist("Artist")%></option>
                <%
    else
%>
                <option value="<%=rsArtist("ArtistID")%>"><%=rsArtist("Art ist")%></option>
                <%
    end if

    rsArtist.movenext

loop

%>
              </select>

              <%

              else

              %>


              <%
set con = server.createobject("ADODB.Connection")
con.open Application("MyString")

strSQL2 = "SELECT * FROM tbl_artists ORDER BY Artist ASC"
Set rsArtist = con.execute(strSQL2)

%>
              <select name="txtArtist" class="TextBox_X" id="txtArtist">
    <%

do while not rsArtist.EOF

    if CStr(request("ArtistID")) = Cstr(rsArtist("Artist")) then
%>
                <option value="<%=rsArtist("ArtistID")%>" selected><%=rsArtist("Artist")%></option>
                <%
    else
%>
                <option value="<%=rsArtist("ArtistID")%>"><%=rsArtist("Art ist")%></option>
                <%
    end if

    rsArtist.movenext

loop

%>
              </select>

            <%

              end if

              %>

thanks in advance.

Adam

  #2 (permalink)  
Old December 5th, 2006, 11:42 AM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What, exactly, is your question?

Woody Z http://www.learntoprogramnow.com
  #3 (permalink)  
Old December 5th, 2006, 07:29 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mmmmmm, im not so sure either. I have made the asumption you wish to detect which options have been selected previously (form has been submitted and inserted values into the DB) in a standard <select> box

If so here is how I do it:

<td>
<% sql = "SELECT incidentId,incidentName FROM incidentType WHERE incidentInactive <> 1 AND incidentId <> 1 ORDER BY IncidentName"
set getInfo = conn.execute(sql)
response.write "<select name='incidents' style='width:215'>"
response.write "<option value='incidents'>Select Incident Type</option>"
do until getInfo.EoF %>
       <option value="<%= getInfo(0) %>" <% if (request.form("incidents") <> "" AND request.form("incidents") <> "incidents") then
                                 if (cint(request.form("incidents")) = cint(getInfo(0))) then
                                                 response.write " selected
                                             end if
                                                          end if %>><%= getInfo(1) %>
<% getInfo.moveNext
loop%>
</select></td>

Wind is your friend
Matt
  #4 (permalink)  
Old December 11th, 2006, 11:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

great, thanks, sorted guys



Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box select affecting avail option in another ebburks Access 4 June 3rd, 2006 05:33 PM
Reloading page when option selected in dropdown chandrasekhar200 Beginning PHP 1 March 10th, 2006 04:52 AM
syntax error on <option selected="selected"> hamid HTML Code Clinic 1 October 13th, 2004 09:20 AM
Fire a macro when an option is selected ashu_gupta75 Excel VBA 1 August 12th, 2004 12:42 AM
Getting select option name not value mildge Javascript How-To 2 April 5th, 2004 10:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.