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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need script go to web page depending on checkbox selected

    Hi

    I am looking for help on a script that has a row of checkboxes, A user can then select 1 or more checkboxes, and then have a button, when clicked allows the user to go the the web page, depending on which checkbox was
    selected.

    Thanks Dave

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Javascript checkbox object tutorial: http://www.javascriptkit.com/jsref/checkbox.shtml
    Javascript if tutorial: http://www.w3schools.com/JS/js_if_else.asp
    To take the browser to a different page use document.location=<url>

    Basically call a function when you click the button. The function checks to see what checkboxes are checked, and takes it to a certain page accordingly.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,155
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    Quote Originally Posted by cwebmaster View Post
    Hi

    I am looking for help on a script that has a row of checkboxes, A user can then select 1 or more checkboxes, and then have a button, when clicked allows the user to go the the web page, depending on which checkbox was
    selected.

    Thanks Dave
    That does not make much sense - how can that work if the user selects more than one checkbox? You want to use radio buttons.

    Code:
    <form name = "myform">
    PAGE 1<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page1.html"><br>
    PAGE 2<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page2.html"><br>
    PAGE 3<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page3.html"><br>
    PAGE 4<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page4,html"><br>
    <input type = "button" name = "but1" value = "Click to go to selected page" onclick = "goPage()">
    </form>
    
    <script type = "text/javascript">
    function goPage() {
    var selected = 0;
    for (var i = 0; i < document.myform.rad1.length; i++) {
    if (document.myform.rad1[i].checked) {
    selected = 1;
    window.location = document.myform.rad1[i].value;
    }
    }
    if (selected == 0) {
    alert ("You must select a radio button!");
    }
    }
    
    </script>
    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 06-13-2008 at 06:54 PM.

  • #4
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    That does not make much sense - how can that work if the user selects more than one checkbox? You want to use radio buttons.

    Code:
    <form name = "myform">
    PAGE 1<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page1.html"><br>
    PAGE 2<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page2.html"><br>
    PAGE 3<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page3.html"><br>
    PAGE 4<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page4,html"><br>
    <input type = "button" name = "but1" value = "Click to go to selected page" onclick = "goPage()">
    </form>
    
    <script type = "text/javascript">
    function goPage() {
    var selected = 0;
    for (var i = 0; i < document.myform.rad1.length; i++) {
    if (document.myform.rad1[i].checked) {
    selected = 1;
    window.location = document.myform.rad1[i].value;
    }
    }
    if (selected == 0) {
    alert ("You must select a radio button!");
    }
    }
    
    </script>
    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    This is what I am trying to do with multiple checkboxes, thanks

    http://www.horizonindustriesltd.com/s/QwikReport.asp


  •  

    Posting Permissions

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