|
-
Jun 29th, 2006, 04:40 PM
#1
Thread Starter
New Member
newbie dynamic dropdowns
hi, i hope someone can make some sense of this. this is my first ever exposure to ASP, so i'm flying blind. what i need to do is have a dropdown that pulls field values from a database and then the user selects a field. what is happenning is that the field gets selected ok, but upon page reload, the display goes back to 'Select Company'. here's the pertinent chunk of code:
gp=Request.QueryString("gp")
c=Request.QueryString("c")
dim conn
dim SQL
dim R
dim RS
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Inetpub\wwwroot\ppsurvey\db\survey.mdb"
set R = Server.CreateObject("ADODB.recordset")
R.CursorType = 1
If gp = 1 Then
SQL = "Select CompanyName, ID, GroupName1, GroupName2, GroupName3, GroupName4, GroupName5 FROM Company WHERE ID = " & c & ""
Else
SQL = "Select DISTINCT CompanyName, ID FROM Company"
End If
R.open SQL, conn
%>
<%
If gp = 1 Then
gpname1=r("GroupName1")
gpname2=r("groupname2")
gpname3=r("groupname3")
gpname4=r("groupname4")
gpname5=r("groupname5")
Else
gpname1="Select a Group"
gpname2=""
End If
%>
<table width="75%" border="0" align="center">
<tr align="center">
<td colspan="2"> <h3>Initial Setup</h3></td>
</tr>
<form action="adduser.asp" method="post" enctype="application/x-www-form-urlencoded">
<tr>
<td align="right">Company:</td>
<td>
<select name="SP" onChange="MM_jumpMenu('parent',this,0)">
<option selected>Select a Company</option>
<%do until r.EOF
tt=r("companyname")
response.write(tt)
id=r("id")
%>
<%
If gp = 1 Then
%>
<option value="adduser.asp?c=<%=id%>&gp=1"><%=tt%></option>
<%
ELSE
%>
<option value="adduser.asp?c=<%=id%>&gp=1"><%=tt%></option>
<%
END IF
r.MoveNext
loop%>
</select>
-
Jun 30th, 2006, 10:44 AM
#2
Fanatic Member
Re: newbie dynamic dropdowns
Try the following. I can't see the difference between your if and else but no doubt there should be, I'm guessing the param gp shouldn't be 1 in the else.
Code:
<%
Dim sSP :sSP=Request.Form("SP")
Dim sVal
Dim sDesc
%>
<select name="SP" onChange="MM_jumpMenu('parent',this,0)">
<option>Select a Company</option>
<%do Until r.EOF
tt=r("companyname")
'response.write(tt)
id=r("id")
If gp = 1 Then
sVal = "adduser.asp?c=" & id & "&gp=1"
sDesc=tt
Else
sVal="adduser.asp?c=" & id & "&gp=1"
sDesc=tt
End If
Response.Write "<option value=""" & sVal & """"
If sSP=sVal Then Response.Write " selected=""selected"""
Response.Write ">" & sDesc & "</option>" & vbNewLine
r.MoveNext
loop%>
-
Jun 30th, 2006, 02:12 PM
#3
Thread Starter
New Member
Re: newbie dynamic dropdowns
thanks a bunch! i'll let you know what happened when i go back to work next week
-
Jul 5th, 2006, 11:17 AM
#4
Thread Starter
New Member
Re: newbie dynamic dropdowns
I'm sad to say that code yielded the exact same results as I had before -- still goes back to "Select Company"
-
Jul 5th, 2006, 12:02 PM
#5
Fanatic Member
Re: newbie dynamic dropdowns
make sure you have removed the selected from this line
VB Code:
<option [HL="#FFFF00"]selected[/HL]>Select a Company</option>
The easiest way to check is to view source and see what the html output is for the select list
I suspect you'll have the first option as above then the option you previously selected saying selected="selected" <-- if you implemented it in the way I suggested.
If not then what you should do is write out the value of sSP and then each val from your select list as you loop through and see if there is a match
-
Jul 5th, 2006, 12:41 PM
#6
Thread Starter
New Member
Re: newbie dynamic dropdowns
I have taken your advice, still, what perplexes me (and thanks by the way), is that it selects the correct value from the database, but no matter what it generates the selected line with "Select Company", even when that line is completely removed from the code. This makes no sense at all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|