Results 1 to 2 of 2

Thread: using IF in Select Option

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default using IF in Select Option

    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

    Code:
    <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
    Code:
    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

  2. #2
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    got my answer on another board, thanks

    Code:
      <%  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%>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •