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 12 of 12
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Help with form leading to urls in active window and new windows

    I've got a problem with the code I'm using and I hope any of you can help me.

    I've got a form with some check-boxes and a submit button. Depending on the box that is checked, the user should be leaded to a new browser window or to an url in the same window.

    The javascript is in a *.js file, and the code is like this:

    ------------------------------------------------------------------------------------
    function Select(){

    if(document.form.CHECKBOX1.checked==true)window.open('http://THEURL1/'+document.form.text.value);

    if(document.form.CHECKBOX2.checked==true)window.open('http://THEURL1/'+document.form.text.value);

    }
    ------------------------------------------------------------------------------------

    So, this way if both check-boxex are checked, the active window will go to an url, and a new window will lead to the second url.

    I don't know if the problem is with the window.open (I thought it should be self.open). And I also tried to add a '_top' or '_same' after the +document.form.text.value. I can't make it work. Any suggestion?. Thanks in advance.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    to open to the same window:

    window.open(url,"_self");

    or:

    location.href = url;

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    with the script I'm using it doesn't work. I cannot write:

    window.open
    ( ' http://THEURL1/ ' +document.form.text.value , " _self " );

    nor:

    window.open
    ( ' http://THEURL1/ ' +document.form.text.value , ' _self ' );

    should be something like:

    window.open
    ( " ' http://THEURL1/ '+document.form.text.value " , " _self ");

    but that doesn't work. I don't know how o use the " and the '.

  • #4
    New to the CF scene
    Join Date
    Feb 2003
    Location
    Dublin
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [code]
    function Select(){

    if(document.form.CHECKBOX1.checked==true) {

    window.location('http://THEURL1/'+document.form.text.value);

    }

    if(document.form.CHECKBOX2.checked==true) {

    window.location('http://THEURL1/'+document.form.text.value);

    }

    }

  • #5
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doesn't work either. Thanks for your posts.

  • #6
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually that is the code I'm using ( with all the {} ). Tke first one was simplified.

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    YOU CAN CHECK THE CODE IN THIS FILE!!!
    Please help me.
    Attached Files Attached Files

  • #8
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can anybody help me?

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    as i've said you before...

    function Search(){
    if
    (document.form.google.checked==true) {
    window.open('http://www.google.com/search?q='+document.form.text.value,"_self");
    //or simply this:
    //location.href='http://www.google.com/search?q='+document.form.text.value;
    }
    if
    (document.form.googleimages.checked==true) {
    window.open('http://images.google.com/images?q='+document.form.text.value);
    }
    }

  • #10
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried that in the file I attached and nothing, the first check-box doesn't work yet, it goes nowhere. I tried both options. Is it working in your PC? If that's so, could you attach your file?. Perhaps that only works once on-line (but I think that is stupit).

    I don't know, I've been here all day sarching for solutions and I can't any more. Thanks Glenngv and others.

  • #11
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    you are using a submit button and <form onSubmit="Search()">
    so the form gets submitted everytime the submit button is clicked.

    you should have made it like <form onSubmit="return Search()">
    and then put return false; at the end of the Search() function to cancel submission

    or to simplify it, remove the onsubmit handler and also the return false in the function then make your button:
    <input type="button" value="Find It!" onclick="Search()">

  • #12
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hey Glenngv I owe you a big one. The world would be better with more people like you. All the best 4 u.


  •  

    Posting Permissions

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