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 to the CF scene
    Join Date
    Jul 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Using checkboxes to open links in new windows.

    Hi all!

    Javascript newbie here. I am trying to setup a javascript code that will open links to items that are checked. Is this possible by client side without using CGI?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Checkboxes are not very suitable for this as the user can select multiple boxes. Prefer to use radio buttons:-


    Code:
    <form name= "myform">
    
    Google <input type = "radio" name = "rad1" onclick = "go()">
    Coding Forums <input type = "radio" name = "rad1" onclick = "go()">
    JavaScriptKit <input type = "radio" name = "rad1" onclick = "go()">
    
    </form>
    
    <script type = "text/javascript">
    
    function go() {
    var sel;
    for (var i =0; i<document.myform.rad1.length; i++) {
    if (document.myform.rad1[i].checked) {
    sel = i;
    }
    }
    if (sel == 0) {window.location = "http://www.google.com"}
    if (sel == 1) {window.location = "http://www.codingforums.com"}
    if (sel == 2) {window.location = "http://www.javascriptkit.com"}
    }
    </script>

    Quizmaster: What is a 12-sided solid figure called?
    Contestant: Well, I know that ten sides is a hexagon. So I'll say an octogon.

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Checkboxes are not very suitable for this as the user can select multiple boxes. Prefer to use radio buttons:-
    Thanks for responding. But the whole point is for the user to HAVE the option to select multiple links, I need it to launch all the links selected by the user.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by xenoche View Post
    Thanks for responding. But the whole point is for the user to HAVE the option to select multiple links, I need it to launch all the links selected by the user.
    What, all at once?

    Code:
    <form name= "myform">
    Google <input type = "checkbox" name = "chk1">
    Coding Forums <input type = "checkbox" name = "chk2">
    JavaScriptKit <input type = "checkbox" name = "chk3">
    <br><br>
    <input type = "button" name = "but1" value = "Launch selected URLs" onclick = "go()">
    </form>
    
    <script type = "text/javascript">
    
    function go() {
    if (document.myform.chk1.checked == true) {window.open("http://www.google.com","window1")}
    if (document.myform.chk2.checked == true) {window.open("http://www.codingforums.com","window2")}
    if (document.myform.chk3.checked == true) {window.open ("http://www.javascriptkit.com","window3")}
    } 
    
    </script>
    You can add attributes to each window, such as width, height, resizable, scrollbars, toolbar etc.

    Example:-

    if (document.myform.chk1.checked == true) {window.open("http://www.google.com","window1",'width=800,height=600,scrollbars=yes,resizable=no,toolbar=yes')}

  • Users who have thanked Philip M for this post:

    xenoche (07-27-2009)

  • #5
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you very much for your help, Phil. Much appreciated. Let me try this code out when I get home from work.

    Thanks again!


  •  

    Posting Permissions

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