1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

on change go to target _blank (diffrent page)

Discussion in 'JavaScript' started by s.jns, Dec 21, 2010.

  1. #1
    Hi,

    How can i make this go to different page on browser?

    <select onChange="javascript:changeLocation(this)" target="_blank">
    <option selected>--Select--</option>
    <option value="http://google.com">google.com</option>
    <option value="http://yahoo.com">yahoo.com</option>
    </select>

    <script type="text/javascript">
    function changeLocation(menuObj)
    {
       var i = menuObj.selectedIndex;
    
       if(i > 0)
       {
          window.location = menuObj.options[i].value;
       }
    }
    </script>
    Code (markup):
    Thanks for the helps
     
    s.jns, Dec 21, 2010 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    
    <script>
        function changeLocation(menuObj)
        {
            window.open(menuObj.options[menuObj.selectedIndex].value);
        }
    </script>
    
    HTML:
     
    tvoodoo, Dec 21, 2010 IP
  3. s.jns

    s.jns Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    yes that work, thanks for this, but a little more with the blank selected option
    <option selected>--Select--</option> also linked to blank page,

    and if i changed to

    <option value="index.php?page=the_page/#" selected>--Select--</option> this is will open the same page with different window/tab

    there another idea that no change for default selected above?
     
    s.jns, Dec 23, 2010 IP
  4. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Leave it to value = "" and change the code to :
    
    <script>
        function changeLocation(menuObj)
        {
            if(menuObj.options[menuObj.selectedIndex].value.length > 0)
            window.open(menuObj.options[menuObj.selectedIndex].value);
        }
    </script>
    
    HTML:
     
    tvoodoo, Dec 23, 2010 IP
  5. s.jns

    s.jns Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    That perfect, thanks
     
    s.jns, Dec 23, 2010 IP
  6. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Your welcome !
     
    tvoodoo, Dec 23, 2010 IP