Log in

View Full Version : using IF in Select Option



taz
04-23-2010, 03:33 PM
Hi, I'm pretty new at ASP. I've got a sheet I'm trying to modify using an IF statement. I tried putting them in, in different ways, but it either shows up in the form or I get the options multiple times


<select onchange="NumberOfDogs_onChange();" name="cmbNumberOfDogs" style="font-family:Arial;font-size:XX-Small;width:70px;">
<option <% if strNumberOfDogs = "1" then response.write "Selected"%> value="1">1</option>
<option <% if strNumberOfDogs = "2" then response.write "Selected"%> value="2">2</option>
<option <% if strNumberOfDogs = "3" then response.write "Selected"%> value="3">3</option>
</select>

i have a variable picked up elsewhere strArea, so I was trying to do something like

if strArea<1000 then
<option <% if strNumberOfDogs = "1" then response.write "Selected"%> value="1">1</option>
elseif strArea <3000 then
<option <% if strNumberOfDogs = "1" then response.write "Selected"%> value="1">1</option>
<option <% if strNumberOfDogs = "2" then response.write "Selected"%> value="2">2</option>
else
<option <% if strNumberOfDogs = "1" then response.write "Selected"%> value="1">1</option>
<option <% if strNumberOfDogs = "2" then response.write "Selected"%> value="2">2</option>
<option <% if strNumberOfDogs = "3" then response.write "Selected"%> value="3">3</option>

I have tried putting the if's in different places, as well as case statement
but usually I end up with my drop down option list as
1
1
2
1
2
3


thanks

taz
04-26-2010, 02:59 PM
got my answer on another board, thanks


<% if strArea < 1000 then %>
<option <% if strNumberOfDogs = "1" then response.write "Selected"%> value="1">1</option>
<% elseif strArea > 1000 and strArea < 3000 then %>
<option <% if strNumberOfDogs = "1" then response.write "Selected"%> value="1">1</option>
<option <% if strNumberOfDogs = "2" then response.write "Selected"%> value="2">2</option>
<%else %>
<option <% if strNumberOfDogs = "1" then response.write "Selected"%> value="1">1</option>
<option <% if strNumberOfDogs = "2" then response.write "Selected"%> value="2">2</option>
<option <% if strNumberOfDogs = "3" then response.write "Selected"%> value="3">3</option>
<% end if%>