HTML Form Help: Drop-down boxes

Discussion in 'HTML & Website Design' started by LeonB, Dec 21, 2008.

  1. #1
    Hi, I am looking for some help with HTML forms, namely forms which mainly comprise of drop-down boxes.

    I know how to create drop-down boxes in forms, though what I want is that each variable in the drop-down box should go to a different URL. For example, if someone selects "variable 1" and then clicks submit, it should go to a different URL than when they select "variable 2" and click submit. I have all the URL's, though I'm just not sure of how to make each variable go to a different URL.

    Can someone help me out with this? If anyone knows of a site which has something similar like this can you please direct me to it so that I can look at he source? Thanks.
     
    LeonB, Dec 21, 2008 IP
  2. islandhopper8

    islandhopper8 Active Member

    Messages:
    100
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #2
    Hi, you need some javascript to do that:
    <select  name="dropdown1">
    <option value="http://www.google.com">http://www.google.com</option>
    <option value="http://www.yahoo.com">http://www.yahoo.com</option>
    </select>
    <input id="Submit1" type="submit"   value="Go Url" onclick="gotoUrl()" />
    <script type="text/javascript">
    function gotoUrl()
    {
    var theUrl = document.getElementById('dropdown1')[document.getElementById('dropdown1').selectedIndex].innerHTML;
    window.location.href=theUrl;
    
    }
    
    </script>
    Code (markup):
    I hope this is what you are looking for.
     
    islandhopper8, Dec 21, 2008 IP
  3. LeonB

    LeonB Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Exactly what I was looking for...thanks heaps!
     
    LeonB, Dec 21, 2008 IP
  4. islandhopper8

    islandhopper8 Active Member

    Messages:
    100
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #4
    I tested it in IE and it worked fine.
    I just tested it in Firefox and it did not work. I cant get it to work so fast in FF but check out this code, if you can do it onchange of the drop down. Here is the code that should work in FF and IE
    <form name="theform">
    <select name="dropdownlist1" size="3"
     OnChange="location.href=theform.dropdownlist1.options[selectedIndex].value">
         <option value="http://www.google.com/">google.com
         <option value="http://www.yahoo.com/">yahoo.com
         <option value="http://www.digitalpoint.com/">digitalpoint.com
    </select>
    </form>
    
    Code (markup):
     
    islandhopper8, Dec 21, 2008 IP