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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble with IF statement 1

Status
Not open for further replies.

VBAPrincess

Programmer
Feb 6, 2004
79
US
I have some code that is populating a combo box with locations and it is supposed to add "selected" to the option that was passed in the query string. However, the "selected" portion is not working.

<%
Dim rsLook
Set rsLook = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT Events.EventID, Events.EventName, Events.StartDate, Events.Status FROM Events " & _
"WHERE (((Events.StartDate)>=Date()) AND ((Events.Status)='open')) ORDER BY Events.StartDate;"
rsLook.open sSQL, oConn
response.Write("<select name='EventID'>")
Do Until rsLook.EOF
if rsLook("EventID")=Request.QueryString("EventID") then
response.write("<option value='" & rsLook("EventID") & "' selected>")
else
response.Write("<option value='" & rsLook("EventID") & "'>")
end if
response.write(rsLook("StartDate") & " -- " & rsLook("EventName") & "</option>" &vbcrlf)
rsLook.MoveNext
Loop
rsLook.close
%>
</select>

Here's a link to the calendar page. When you click on the "click here to RSVP" for any of the events, the RSVP form comes up and the Event combo box should have the event you wish to RSVP for already selected in the combo. Here's what I know:
--> The event ID is appearing in the URL (ex: rsvp.asp?eventid=3)
--> I have a hidden field in my form that also has
value="<%= Request.QueryString("EventID") %>"
and when I view source, the value is correct.

I've been banging my head for too long now. I need fresh eyes to take a look and tell me what's wrong. I have this same code (with one exception: I'm not getting a QueryString value) on a page in the admin section and it works just fine.

Thanks in advance!


Diana
VBA Princess
-- I'm hoping to grow up to be a Goddess!
 
how about this:

Code:
response.write("<option value="""&'" & rsLook("EventID") & "'&""" selected>")

-DNG
 
oops...sorry...this one:
Code:
response.write("<option value="""&rsLook("EventID")&""" selected>")

-DNG
 
Thanks, but no, that didn't work. It appears to me that the

[tt]if rsLook("EventID")=Request.QueryString("EventID") then[/tt]

is always returning false. I've modified the code to output the value for rsLook("EventID") and for Request.QueryString("EventID") and can visually see where they match, but it seems like the IF statment is always testing false. I modified it to say if <> then and every option value showed selected.

Thanks.

Diana
VBA Princess
-- I'm hoping to grow up to be a Goddess!
 
Not sure if this will help, but try to convert them to the same data type and see if they match. For example
Code:
if cStr(rsLook("EventID"))=cStr(Request.QueryString("EventID")) then

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
THANK YOU! I knew I needed some fresh eyes here. I should have thought of that. The database is using a number and the query string appears to be too. I should have gone ahead and just made them the same type.

I really appreciate the help!


Diana
VBA Princess
-- I'm hoping to grow up to be a Goddess!
 
Glad that helped! [thumbsup]

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
i was thinking of this:

if rsLook("EventID")=cInt(Request.QueryString("EventID")) then

since Request.Querystring is already a string...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top