SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: If Statement

  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If Statement

    Is there a way that I can use ASP to show a second drop down menu if someone selects one of the above drop downs? Here is the ASP code simplified:

    Code:
    <tr>
      <td>
        <select name="hear_about">
          <option value="Family/Friend">Family/Friend</option>
          <option value="Web Site">Web Site</option>
          <option value="Facebook">Facebook</option>
          <option value="Twitter">Twitter</option>
        </select>
      </td>
    </tr>
    <%
    If hear_about = Facebook Then
        Response.Write('
    <tr>
      <td>
        <select name="health_center">
          <option value="Option 1">Option 1</option>
          <option value="Option 2">Option 2</option>
          <option value="Option 3">Option 3</option>
        </select>
      </td>
    </tr>
    ')
    End If
    %>
    Any help would be awesome!!!

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe something like this would help you

    multiple dependent lists

  3. #3
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately this is now what I was looking for. I would like for a second drop down menu to appear if you select one of the options above. Otherwise the second drop down menu will not appear. I sincerely appreciate the help, but does anyone have a solution for this problem?

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ASP runs on the server. So the only way that ASP can handle such a request is if making a selection from the first list then makes a request to an ASP script on the server to get the data for the second list.

    How is the data for the first (and second, and any other) list defined? Is the data pulled from a database? Is it fixed data (hard-coded)? If the data comes from a database then it sounds to me like you need a mix of ASP (to get the data) and AJAX (Javascript code to use the ASP code and get the data) so that the creation and display of the second list is seamless.

    The only other way is for a selection from the first list to automatically submit the form to get the value, and then show the second list. The link that webber advised does do this. It only needs some modification to prevent showing the second list unless an item has been selected from the first list.

    <% If showSubcat = false Then %>

    Move that to before the start of the second (SubCategory) <SELECT> (and the End If to after the <?SELECT>) and you have achieve what you need.

    Have a go at coding your own version and we'll help you get it working. If you're wanting someone to write the code for you, try the Marketplace?
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,021
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rockwilda View Post
    Unfortunately this is now what I was looking for. I would like for a second drop down menu to appear if you select one of the options above. Otherwise the second drop down menu will not appear. I sincerely appreciate the help, but does anyone have a solution for this problem?
    The solution you're looking for is a combination of Javascript and Server-side ASP code. It's commonly referred to as AJAX but being that ASP is an older tech there aren't a lot of off the shelf solutions. I've done it several times but I had to do the coding myself and it gets messy.

    Here's the theory... This might be a little technical so hopefully it makes sense to you:

    What you do is add an action to your first dropdown so that when a dropdown item is selected a JavaScript function runs that uses XMLHttpRequest(), ActiveXObject("Msxml2.XMLHTTP"), or ActiveXObject("Microsoft.XMLHTTP") depending on the browser to run an ASP page in the background. This ASP page probably runs a query against your database to create the second dropdown menu.

    On a successful query you fire another JavaScript function that uses document.getElementById(second-dropdown-location).innerHTML to insert the new dropdown.

    So armed with the theory, you can either try to build this functionality yourself or maybe check with the JavaScript forum for a bit of help doing this.

    You can probably use the jQuery library to help out. Here is a helpful link: LINK
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello.

    If Request("select") = "1" Then
    Response.Write "1"
    Else If Request("select") = "2" Then
    Response.Write "2"
    ...
    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
  •