Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

dynamic <option selected> thing in Classic ASP

I can't figure out why this doesn't work.. it's probably so simple...

1:59 pm on May 26, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 13, 2004
posts: 97
votes: 0

Hi folks,

I'm hoping someone can help me here.. I'm having a little problem getting something to work in Classic ASP...

here's the code snippit:

dim intTotalfamilies, rs_disp
intTotalfamilies = rs_afamlist.RecordCount
for aloop = 1 to intTotalfamilies
If not rs_afamlist.eof then
thefamilynumber = rs_afamlist("familyNumber")%>
<option value="sample.asp?whatFamToShow=<%=thefamilynumber%>" <%if whatFamToshow = thefamilynumber then%> selected <%end if%>><%=rs_afamlist("familyDisplayedName")%></option>
<% else
response.write ("oops - list is broken")
end if

Basically.. it works.. the only bit that won't work is the tiny little IF-Then bit of logic that writes "selected" inside of an <option> that says it's selected .. I can't figure out why..

I've tested and debugged.. the variables are all passing correctly (I commented out <thefamilynumber is <%=thefamilynumber%> and whatFamToshow is <%=whatFamToShow%> - and in view source of the generated page.. the numbers all showed just as they should..

but the when I use the same variables for <%if whatFamToshow = thefamilynumber then%> selected <%end if%> then I NEVER get any condition where the computer writes selected.. even when I know there's always at least 1 instance when whatFamToshow = thefamilynumber.

it's quite annoying. and yes.. i've tried writing it : selected="selected" . same thing.. what am I doing wrong?

it's something silly and obvious isn't it?

8:05 pm on May 26, 2009 (gmt 0)


WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
votes: 3

This forces the data types to be integers of the variables. Which should allow the compare to work.

<%if cint(whatFamToshow) = cint(thefamilynumber) then%>

8:14 pm on May 26, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 13, 2004
posts: 97
votes: 0

DAMN! of course.. I've been having difficulties with file type mismatches all day with my sql strings I can't believe I didn't sus out that it was number / string issue..

I've just put that in.. and of course, it works great!

thanks very much for your help!

S42 :-)