Web Analytics Made Easy -
StatCounter Checkboxes do redirect - CodingForum

Announcement

Collapse
No announcement yet.

Checkboxes do redirect

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checkboxes do redirect

    I need a script that redirects me to a page depending on which checkboxes have been checked. For example, I have a pege with 4 checkboxes: 1,2,3,4. If the user checks '1', he will be redirected to '1.html'. If the users checks '1' and '2' checkboxes, he will be redirectetd to '12.html'. If the user checks all checkboxes, he will be redirected to '1234.html' and so. Thanks in advance.

    Apolinho

  • #2
    Possibilities of Pages

    What are the possibilities of page names..

    ckbx1+ckbx3 = 13.html
    ckbx1+ckbx2 = 12.html

    what are the possiblities of the check boxes?

    1.html
    2.html
    3.html
    4.html
    1234.html

    that is it right?
    Younger is better, I think. Sometimes.

    Comment


    • #3
      Richard, the possibilities are:

      chkbox1 alone= 1.html
      chkbox2 alone= 2.html
      chkbox3 alone = 3.html
      chkbox4 alone = 4.html
      chkbox1 + chkbox2 = 12.html
      chkbox1 + chkbox3 = 13.html
      chkbox1 + chkbox4 = 14.html
      chkbox2 + chkbox3 = 23.html
      chkbox2 + chkbox4 = 24.html
      chkbox3 + chkbox4 = 34.html

      Okay?

      Comment


      • #4
        Soyy, I've made a mistake
        Richard, the possibilities are:

        chkbox1 alone= 1.html
        chkbox2 alone= 2.html
        chkbox3 alone = 3.html
        chkbox4 alone = 4.html
        chkbox1 + chkbox2 = 12.html
        chkbox1 + chkbox3 = 13.html
        chkbox1 + chkbox4 = 14.html
        chkbox2 + chkbox3 = 23.html
        chkbox2 + chkbox4 = 24.html
        chkbox3 + chkbox4 = 34.html
        chkbox1+ chkbox2+ chkbox3 = 123.html
        chkbox1+ chkbox2+ chkbox4 = 124.html
        chkbox1+ chkbox3+ chkbox4 = 134.html
        chkbox1+ chkbox2+ chkbox3 = 123.html
        chkbox2+ chkbox3+ chkbox4 = 123.html
        chkbox1+ chkbox2+ chkbox3 + chkbox4 = 1234.html

        Boring, isn't it?

        Comment


        • #5
          Okay...

          Now that I understand this a little bit better..

          I am thinking that you will have to call for a function that checks to see which chkbxs have been selected.. and then by which are selected would determin the site..

          <script language="JavaScript">
          function openPage() {
          // the function properties in here
          onClick=window.// other properties
          }
          <input type=checkbox name="// possible number(s)>
          <body onLoad="openPage()">

          That is a real sketchy dipiction of what the codeing would look like. Maybe you should wait until another member with more knowledge to help.. I am not too sure if that will work.

          Hope that I helped.
          Younger is better, I think. Sometimes.

          Comment


          • #6
            script:

            function openPage(){
            var frm = document.yourformname;
            var page="";
            for (var i=1;i<=4;i++){
            objChk = eval("frm.chkbox"+i);
            if (objChk.checked) page+=""+objChk.value;
            }
            page+=".html";
            location.href=page;
            }


            html:

            <input type="checkbox" name="chkbox1" value="1">Checkbox 1
            <input type="checkbox" name="chkbox2" value="2">Checkbox 2
            <input type="checkbox" name="chkbox3" value="3">Checkbox 3
            <input type="checkbox" name="chkbox4" value="4">Checkbox 4

            <input type="button" value="Open" onclick="openPage()">
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              aha

              I was missing about half of the form properties, but I had the right idea in mind.... I will have to change my quote..
              Younger is better, I think. Sometimes.

              Comment


              • #8
                this is you html :
                <form onsubmit="return lol()">
                Checkbox: <input type="checkbox" id="myCheck"/>
                <input type="submit" value="Submit" />
                </form>



                this is your Javascript :

                function lol()
                {
                if(document.getElementById("myCheck").checked == true)
                {
                window.location.href="http://www.google.com";
                }
                else
                {
                return false;
                }
                }
                Last edited by VIPStephan; Aug 13, 2015, 10:07 AM. Reason: removed link

                Comment


                • #9
                  An alternative solution:

                  Code:
                  <!DOCTYPE html>
                  <html lang="en">
                  <head>
                  <meta charset="UTF-8" />
                  
                  <title> Checkbox Redirect </title>
                  
                  </head>
                  <body>
                  Checkboxs: 
                  <label> <input type="checkbox" name="cbox" value="1"> 1 </label>
                  <label> <input type="checkbox" name="cbox" value="2"> 2 </label>
                  <label> <input type="checkbox" name="cbox" value="3"> 3 </label>
                  <label> <input type="checkbox" name="cbox" value="4"> 4 </label>
                  <button onclick="initEvents()">Collect</button>
                  
                  <script type="text/javascript">
                  
                  function initEvents() {
                    var str = '';
                    var sel = document.getElementsByName("cbox");
                    for (var i=0; i<sel.length; i++) {
                      if (sel[i].checked) { str += sel[i].value; }
                    }
                    if (str == '') { return; } else {
                      alert(str+'.html');
                  //    document.location.href = str+'.html';  // use this instead of alert
                    }
                  }
                  </script>
                  </body>
                  </html>

                  Comment

                  Working...
                  X