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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Onchange Event in Option Value to open new window

    Hi All

    I want a dropdown box with links in, some links will open in the same window and others I want to open in a new window.

    I have found some code to follow for opening in the same window, but as some of my links need to open in a new window I can't seem to get it to work...

    Here is my code (well not mine really!)

    PHP Code:
    <SCRIPT LANGUAGE="javascript">
      <!--
      function 
    gotoLink() { 

      
    // Get the currently selected item from the menu 

      
    goingTo document.quickMenu.link.options[document.quickMenu.link.selectedIndex].value;

      
    // If the currently selected item is not valid, do nothing. Otherwise, 
      // redirect the browser to the newly selected page. 

      
    if (goingTo == ""
        { return; } 
      else 
        { 
    self.location goingTo; }

      }
      
    // -->
    </SCRIPT>

    </head>
    <body>

    <FORM NAME="quickMenu">
      <LABEL>Get information from <A HREF="http://www.yahoo.com">Yahoo</A> about one of the states:
    </label>
      <SELECT NAME="link" ONCHANGE="gotoLink()">
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alabama/">Alabama</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alabama/" target="_blank">Alabamatttt</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alabama/">Alabama</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Arizona/">Arizona</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Arkansas/">Arkansas</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/California/">California</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Colorado/">Colorado</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Connecticut/">Connecticut</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Delaware/">Delaware</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Florida/">Florida</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Georgia/">Georgia</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Hawaii/">Hawaii</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Idaho/">Idaho</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Illinois/">Illinois</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Indiana/">Indiana</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Iowa/">Iowa</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Kansas/">Kansas</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Kentucky/">Kentucky</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Louisiana/">Louisiana</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Maine/">Maine</OPTION>
        <OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Maryland/">Maryland</OPTION>
        </SELECT>
    </FORM>
    </body> 
    Hope you can help - as you can see the target="_blank" doesn't work....

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In the example below Alabama opens in the main window, Alaska opens in a new window.

    patrick

    Code:
    <html>
    <head>
    <script type="text/javascript">
      <!--
      function newWin(x){
      window.open(x, "", "height=400px, width=500px")
      }	
      // -->
    </script>
    
    </head>
    <body>
    
    <form name="quickMenu">
      <label>Get information from <A HREF="http://www.yahoo.com">Yahoo</A> about one of the states:
    </label>
      <select name="link">
        <option value="http://dir.yahoo.com/Regional/U_S__States/Alabama/" onclick="self.location=this.value">Alabama</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Alaska/" onclick="newWin(this.value)">Alaska</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Arizona/">Arizona</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Arkansas/">Arkansas</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/California/">California</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Colorado/">Colorado</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Connecticut/">Connecticut</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Delaware/">Delaware</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Florida/">Florida</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Georgia/">Georgia</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Hawaii/">Hawaii</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Idaho/">Idaho</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Illinois/">Illinois</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Indiana/">Indiana</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Iowa/">Iowa</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Kansas/">Kansas</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Kentucky/">Kentucky</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Louisiana/">Louisiana</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Maine/">Maine</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Maryland/">Maryland</option>
        </select>
    </form>
    </body>
    </html>
    Last edited by mpjbrennan; 04-23-2004 at 01:08 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi - thanks for the reply - but I can't get it to work....


    I've also tried to change the onclick to onchange and its still won't work - any ideas?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoops! - you're right , it only works in Mozilla. I should have tested it in IE before posting.

    Need to think.....

    patrick

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers - look forward to your response

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Holty,

    Try this version - it checks out in Mozilla and IE6. If you want a new window give the relevant option the title newWin, otherwise give it the title "".

    patrick

    Code:
    <html>
    <head>
    <script type="text/javascript">
      <!--
      function goLink(x, y){
      if(!x){return false}
      y == "newWin" ? window.open(x, "", "height=400px, width=500px") : self.location = x
      document.getElementById("select1").selectedIndex = 0
      }
      // -->
    </script>
    
    </head>
    <body>
    
    <form name="quickMenu">
      <label>Get information from <A HREF="http://www.yahoo.com">Yahoo</A> about one of the states:
    </label>
      <select id="select1" name="link" onchange="goLink(this.options[this.options.selectedIndex].value,this.options[this.options.selectedIndex].title )">
        <option title="" value="" selected="selected">Select</option>
        <option title="" value="http://dir.yahoo.com/Regional/U_S__States/Alabama/">Alabama</option>
        <option title="newWin" value="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Arizona/">Arizona</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Arkansas/">Arkansas</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/California/">California</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Colorado/">Colorado</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Connecticut/">Connecticut</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Delaware/">Delaware</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Florida/">Florida</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Georgia/">Georgia</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Hawaii/">Hawaii</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Idaho/">Idaho</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Illinois/">Illinois</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Indiana/">Indiana</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Iowa/">Iowa</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Kansas/">Kansas</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Kentucky/">Kentucky</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Louisiana/">Louisiana</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Maine/">Maine</option>
        <option value="http://dir.yahoo.com/Regional/U_S__States/Maryland/">Maryland</option>
        </select>
    </form>
    </body>
    </html>
    patrick


  •  

    Posting Permissions

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