Click to See Complete Forum and Search --> : select box


jrthor2
04-25-2006, 08:52 AM
I have a select box that I am trying to get the option to be selected if my categories match from the database and the url, but I can't seem to get it working. Below is my code, so if the catg in the url = the id from the db, then I want the option to be selects.

<select id="category_id" size="1">
<%
SQLstmt = "SELECT * from Categories order by category asc"

Set rs = conn.execute(SQLstmt)

Do while NOT rs.EOF
id = rs("category")
category_nme = rs("category_description")
%>
<option value="<%=id%>"<%if (Request.QueryString("catg")) = id then%> selected <%end if%>><%= category_nme%></option>
<%
rs.MoveNext
Loop
rs.Close
Set conn = nothing
Set rs = Nothing
Set SQLstmt = nothing
%>
</select>


Thanks!

zingmatter
04-25-2006, 09:11 AM
The most likely thing is that the querystring value is a string data type while id is not, so they'll never compare. Try doing

if (Request.QueryString("catg")) = CStr(id) then ...

Hope this helps

jrthor2
04-25-2006, 09:17 AM
That seemed to have worked, my option value is now:

<select id="category_id" size="1">
<option value="1">Homepage</option> <option value="2" selected="selected">About Us</option> <option value="3">Cool Products</option>
</select>

But for some reason, the select box is not showing as that being selected when that page displays. Any ideas as to why??

Thanks again!!

UPDATE: this seems to work in IE, but in FireFox, it does not show as selected.

zingmatter
04-25-2006, 11:02 AM
Are you using xhtml? If not then selected="selected" may not work for html 4. Just a thought anyway.

jrthor2
04-25-2006, 11:04 AM
Yes, I am using XHTML 1.0 Transitional.