|
Subject:
|
option selected from a select box
|
|
Posted By:
|
Adam H-W
|
Post Date:
|
12/5/2006 4:31:05 AM
|
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("Artist")%></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("Artist")%></option> <% end if
rsArtist.movenext
loop
%> </select> <% end if %>
thanks in advance.
Adam
|
|
Reply By:
|
woodyz
|
Reply Date:
|
12/5/2006 10:42:29 AM
|
What, exactly, is your question?
Woody Z http://www.learntoprogramnow.com
|
|
Reply By:
|
mat41
|
Reply Date:
|
12/5/2006 6:29:06 PM
|
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
|
|
Reply By:
|
Adam H-W
|
Reply Date:
|
12/11/2006 10:09:05 AM
|
great, thanks, sorted guys
|