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 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    target = blank problem

    Hi there,

    I have the form below and i want when the checkbox is checked, or when the second drop down menu selected "_blank", to open in a new window.
    Can somebody help??

    thank you


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <SCRIPT LANGUAGE=javascript>
    function go() {

    location=document.form1.menu.options[document.form1.menu.selectedIndex].value;
    target=document.form1.menu2.options[document.form1.menu2.selectedIndex].value;

    // OR USING A BOX THE CODE WOULD BE????
    // if (document.form1.checkbox.checked == true) { target="blank");

    }
    </SCRIPT>
    </head>

    <body>
    <form name="form1" >
    <select style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" name="menu">
    <option value="http://www.google.com" selected>Gooooogleit</option>
    <option value="http://www.yahoo.com">Yahoooooit</option>
    </select>
    <input style="font-size:12px;color:#ffffff;font-family:verdana;background-color:#006699;" type="button" onClick="go()" value="Go">
    <p>&nbsp;</p>

    <select style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" name="menu2">
    <option value="parent" selected>parent</option>
    <option value="blank">blank</option>
    </select>


    <input type="checkbox" name="checkbox" value="_blank" checked="checked" />

    </form>

    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    location is a reserved word, so try this:
    Code:
    <SCRIPT LANGUAGE=javascript>
    function go() {
    loc=document.form1.menu.options[document.form1.menu.selectedIndex].value;
    target=document.form1.menu2.options[document.form1.menu2.selectedIndex].value;
    if (target=='blank') var win = window.open(loc);
    else location.href=loc;
    }
    </SCRIPT>

  • #3
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts
    dosn't "blank" have an underscore before it? (_blank) or is that html?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It does have the underscore in front but in this case it doesn't really matter as the script posted as a solution is using window.open for the new window rather than just setting the forms target to _blank besides in HTML Strict and XHTML Strict the target attribute has been deprecated because it was considered a behavior. Since JS is good at behaviors we use js to create the new windows.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    It does have the underscore in front but in this case it doesn't really matter as the script posted as a solution is using window.open for the new window
    Fwiw, it does make a difference.

    As in markup, the second, target argument of the window.open method functions similarly to the target attribute in markup.

    e.g.
    Code:
    window.open('blah.html','blank'); // one reusable window
    
    window.open('blah.html','_blank'); // new window every time


  •  

    Posting Permissions

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