Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with If Statement 1

Status
Not open for further replies.

iisman

Technical User
Mar 6, 2005
85
CA
Hello,

I have the following code - a drop-down list populated from DB. It submits the form to the same page. I want to have the drop-down menu write in select="selected" for the item that was chosen, but i can not get this to work! Can anyone see why this may be?

Code:
<form name="stats" method="post" action="voteadmin.asp?content=2">

<font class="contentred">&nbsp;&nbsp;Choose Poll:</font>
<%
set conn = server.createobject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("../../employeesurvey/vote/polls.mdb")

set objRS = server.createobject("adodb.recordset")
strsql = "SELECT * FROM Questions"
objRS.open strsql, conn, 2, 2

dim tur
tur = Request.Form("stat")
'response.write tur
%>

&nbsp;<select name="stat" class="inputbox" onChange="this.form.submit();">
<%
Do While Not objRS.EOF
%>
<option value="<%=objRS("ID")%>" 

<%
if objRs("ID") = tur then 
response.write("select=""selected""")

end if
%> 

>

<%=objRS("question")%>
</option>
<%objRS.movenext%><% loop %>
</select>
<input type="hidden" name="showresults" value="45" />

</form>

thanks in advance for having a look.
 
Perhaps this ?
<%
If objRs("ID") = tur Then
Response.Write(" selected")
End If
%>

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks for responding. Negative on that one. I check the html source code that is output to the browser, and nothing in that response.write is being output ... which leads me to beleive that there is a problem with one of the variables of with the if statement.

I have checked the tur variable with a response.write, and it does return the numerical value that i have intended,l so I dont think that is the issue...

any other help/suggestions would be appreciated.
 
>[tt]response.write("select=""selected""")[/tt]
[tt]response.write("select[red]ed[/red]=""selected""")[/tt]
 
Also as no space is prepared infront of it, add the space to that line. (I make it standout here.)
[tt] response.write(" " & "selected=""selected""")[/tt]

 
Thanks tsuji for the response.

no juice with any of that :(

like I said, nothing at all in that response.write statement is getting output to the browser, so even though I have the selected statement correct now, it isnt being output!

 
And this ?
<%
If Trim(objRs("ID")) = Trim(tur) Then
Response.Write(" selected")
End If
%>

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV!

That did the trick! I should have tried that myself! I have added that trim function to my list of troubleshooting tools!

Thank you very much for all of your help everyone!

It is greatly appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top