Results 1 to 3 of 3

Thread: Dropdown list with different target locations.

  1. #1
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Dropdown list with different target locations.

    Okay Javascript Masters, here's one for you! Lets say I want something like this:
    Code:
    <FORM NAME="URLlist">
    <SELECT NAME="droplist">
    <OPTION SELECTED="SELECTED" VALUE=" ">Select a Destination!</OPTION>
    <OPTION VALUE="http://www.yoururl.com">Your Discription</OPTION>
    <OPTION VALUE="http://www.yoururl1.com">Your Discription1</OPTION>
    <OPTION VALUE="http://www.yoururl2com">Your Discription2</OPTION>
    </SELECT><INPUT TYPE="BUTTON" VALUE="Go!" ONCLICK="GotoURL(this.form)">
    <SCRIPT LANGUAGE="JavaScript"> 
    <!--
    function GotoURL(dl) { 
    // FRAMES - To open a selection in a document that uses frames 
    // change top.location.href to parent.putyourframenamehere.location.href
    top.location.href = dl.droplist.options[dl.droplist.selectedIndex].value;
    } 
    // -->
    </SCRIPT>
    </FORM>
    Except I want the different values to open in different locations. Say a couple of them should open in the parent (of a frameset), some should open in a new window and so on.

    Is this possible with the above code or am I dreaming?
    Last edited by Sartavius; 10-27-2011 at 11:03 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    After a fashion, yes.

    Make the values comma delimited and parse the values into an open method, like:

    Code:
    <form name="URLlist">
    <select name="droplist">
    <option selected="selected" value=" ">Select a Destination!</option>
    <option value="http://www.yoururl.com,_new">Your Discription</option>
    <option value="http://www.yoururl1.com,_top">Your Discription1</option>
    <option value="http://www.yoururl2com,yourframenamehere">Your Discription2</option>
    </select><input type="button" value="go!" onclick="GotoURL(this.form)">
    <script type="text/javascript">
    function GotoURL(dl) { 
    	var val = dl.droplist.value.split(',');
    	open(val[0], val[1]);
    } 
    </script>
    </form>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Sartavius (10-26-2011)

  4. #3
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Once again, your javascript omnipotence reigns supreme!

    Seriously - thanks a million!

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
  •