Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    85
    Thanks
    15
    Thanked 5 Times in 5 Posts

    Opening Items from a Dropdown List in a New Window

    I haven't been able to find anything about this on here or clear direction on the net, so I'm hoping y'all can help me out.

    I have a dropdown list that I use to navigate pages on an external website. Currently, my dropdown list will open a new page in my current window. I want to be able to open the page in a new window.

    I'm sure it's a simple fix, but being somewhat of a noob to Javascript I can't figure out how to solve it.

    Here's what I have for the navigation dropdown:

    Code:
    <FORM 
         ACTION="../cgi-bin/redirect.pl" 
         METHOD=POST onSubmit="return dropdown(this.gourl)">
    <SELECT NAME="gourl">
    
    <OPTION VALUE="">Make Your Selection
    <OPTION VALUE="http://url1.html>Choice 1
    <OPTION VALUE="http://url2.html>Choice 2
    <OPTION VALUE="http://url3.html">Choice 3
    
    </SELECT>
    
    <INPUT TYPE=SUBMIT VALUE="Go">
    </FORM>
    And here's what I have in the header:

    Code:
    <SCRIPT TYPE="text/javascript">
    <!--
    function dropdown(mySel)
    {
    var myWin, myVal;
    myVal = mySel.options[mySel.selectedIndex].value;
    if(myVal)
       {
       if(mySel.form.target)myWin = parent[mySel.form.target];
       else myWin = window;
       if (! myWin) return true;
       myWin.location = myVal;
       }
    return false;
    }
    //-->
    </SCRIPT>
    Any ideas?

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    I think window.open() is what you are looking for, although your if statements have me somewhat confused:

    Code:
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <FORM 
         ACTION="../cgi-bin/redirect.pl" 
         METHOD=POST onSubmit="return dropdown(this.gourl)">
    <SELECT NAME="gourl">
    
    <OPTION VALUE="">Make Your Selection</OPTION>
    <OPTION VALUE="http://url1.html">Choice 1</OPTION>
    <OPTION VALUE="http://url2.html">Choice 2</OPTION>
    <OPTION VALUE="http://url3.html">Choice 3</OPTION>
    
    </SELECT>
    
    <INPUT TYPE=SUBMIT VALUE="Go">
    </FORM>
    <script type="text/javascript">
    
    function dropdown(mySel)
    {
    var myWin, myVal;
    myVal = mySel.options[mySel.selectedIndex].value;
    if(myVal)
       {
       if(mySel.form.target)myWin = parent[mySel.form.target];
       else myWin = window.open();
       if (! myWin) return true;
       myWin.location = myVal;
       }
    return false;
    }
    </script>
    </body>
    </html>

  • Users who have thanked xelawho for this post:

    dougcollins02 (12-08-2011)

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    85
    Thanks
    15
    Thanked 5 Times in 5 Posts
    Thanks for the help! It's working splendidly. I really appreciate you taking the time to give me a hand.

    I know my "if" statements need some work. I feel good for someone just learning Javascript, but know I have a long ways to go.


  •  

    Tags for this Thread

    Posting Permissions

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