Forum Moderators: open

Message Too Old, No Replies

Setting a Select Box dynamically

why does one work, but not the other?

         

txbakers

9:41 pm on Aug 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When building a select box manually, I can dynamically set the "selected" based on a database value:

<select>
<option value="1" <%= rsRS("val")=="1"? "selected" : "" %>1
<option value="2" <%= rsRS("val")=="2"? "selected" : "" %>2
<option value="3" <%= rsRS("val")=="3"? "selected" : "" %>3
</select>

This works without a problem.

However, when the box is built dynamically, and I try to use the Request value, it doesn't:

<select>
<% while (!rs.EOF){%>
<option value="<%=rs("val")%>" <%=rs("val") == Request("e")? "selected" : ""%>><%=rs("val")%>
<% rs.MoveNext(); } %>
</select>

Does it have anything to do with using the Request object? When I view both values they are identical. I tried parseInt, String, and a few other functions to make sure they matched, but still the "selected" never shows.

Could I put the Request("e") value into a variable and use that? I haven't tried that.

ziggystardust

10:52 am on Aug 8, 2004 (gmt 0)

10+ Year Member



It should work...

Hmm, have you tried using the String equals method?

//ZS

txbakers

3:31 pm on Aug 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried the String(rs("val")).equals(String(Request("v"))) but it didn't work since I'm in Javascript, not Java.

I used client side javascript to set the value. That seems to work.

duckhunter

7:28 pm on Aug 8, 2004 (gmt 0)

10+ Year Member



Write a simple function that compares two values and returns "selected" if true and blank if false. Pass in as params your Value & Request var into the function and let it decided whether to return "" or "selected"

txbakers

9:06 pm on Aug 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep that's what I'm doing. I'd prefer to do it without client side JS, but oh well.