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
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Drop-down list not opening new window

    New member here. Hope y'all can help with a frustrating issue I have.

    SYSTEM INFO:
    I'm on an Apple MacBook Pro running OS X v10.7.3 (Safari v5.1.3).

    PURPOSE:
    I want to create a drop-down list of web sites I like. When the user selects an item, I want the browser to open a new window (or tab) with the URL provided.

    THIS WORKS (but, as expected, content is placed in current window):
    <form>
    <select name="URL" OnChange="location.href=this.form.URL.options[selectedIndex].value">
    <option value="" selected><b>Your network info ...</b></option>
    <option value="http://www.aws.com/support/faq/software/ip.asp">Your IP address</option>
    <option value="http://www.beelinebandwidthtest.com/">Your bandwidth speed (option 1)</option>
    <option value="http://reviews.cnet.com/Bandwidth_meter/7004-7254_7-0.html">Your bandwidth speed (option 2)</option>
    <option value="http://www.spamhaus.org/lookup.lasso">Spamhaus IP check</option>
    </select>
    </form>


    BUT THIS DOESN'T WORK … WHY NOT? Expecting a new window (or tab) to be created.:
    <form>
    <select name="URL" OnChange="window.open(this.form.URL.options[selectedIndex].value)">
    <option value="" selected><b>Your network info ...</b></option>
    <option value="http://www.aws.com/support/faq/software/ip.asp">Your IP address</option>
    <option value="http://www.beelinebandwidthtest.com/">Your bandwidth speed (option 1)</option>
    <option value="http://reviews.cnet.com/Bandwidth_meter/7004-7254_7-0.html">Your bandwidth speed (option 2)</option>
    <option value="http://www.spamhaus.org/lookup.lasso">Spamhaus IP check</option>
    </select>
    </form>


    FYI … INTERESTINGLY, THE "window.open" CODE *DOES* WORK FOR A BUTTON. HMMMM.
    <form>
    <input type="button" value="Open Window" onclick="window.open('http://www.about.com')">
    </form>


    Anyone have a suggestion on what I'm doing wrong with the <SELECT OnChange=window.open()> event?

    -- Udee

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Your code does work on other clients. Try simplifying it to window.open( this.value )

  • #3
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    910
    Thanks
    0
    Thanked 120 Times in 119 Posts
    per definition window.open requires an URL and a window name. eg.:
    window.open('http://www.google.com/', 'NewWindow');

    Maybe Apple for OSx is very strict here.

    Or maybe you have checked "Block Extra Windows" under settings

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    You only have to open the popup when option value is not empty to exclude the first option.

    Code:
    <select name="URL" onchange="if (this.value) window.open(this.value, '_blank');">

  • #5
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    BEST EXAMPLE YET! But...

    I've been scouring the web for days looking for a javascript dom example just like this. I've seen so many, but I tested this one and it is (almost) perfect!

    It's almost perfect for me because I really don't want my form to submit onchange. How do I implement a submit button, instead?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Is this what you needed?
    Code:
    <form>
    <select name="URL">
    <option value="">Your network info ...</option>
    <option value="http://www.aws.com/support/faq/software/ip.asp">Your IP address</option>
    <option value="http://www.beelinebandwidthtest.com/">Your bandwidth speed (option 1)</option>
    <option value="http://reviews.cnet.com/Bandwidth_meter/7004-7254_7-0.html">Your bandwidth speed (option 2)</option>
    <option value="http://www.spamhaus.org/lookup.lasso">Spamhaus IP check</option>
    </select>
    <input type="button" value="Open Window" onclick="if (this.form.URL.value) window.open(this.form.URL.value);" />
    </form>


  •  

    Posting Permissions

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