help checkbox

Discussion in 'JavaScript' started by donteatchicken, Jul 19, 2006.

  1. #1
    I have 3 checkboxes

    I need a javascript that will pop up a message or something if the end user tries to select boxes 1 and 3

    2 and 3 is ok, 1 and 2 is ok, or just 1 2 or 3 is ok, but 1 and 3 is NOT ok..

    ANY help would be greatly appriciated!

    Thanks..
     
    donteatchicken, Jul 19, 2006 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Using the following sample names for the form and checkboxes:
    <form name="myform" id="myform" action="" method="post">
    <input type="checkbox" name="chk[]" />
    <input type="checkbox" name="chk[]" />
    <input type="checkbox" name="chk[]" />
    </form>
    Code (markup):
    <script type="text/javascript">
    function mycheck ()
    {
       var mycheckbox = document.myform.elements["chk[]"];
       if (mycheckbox[0].checked && mycheckbox[2].checked)
       {
          alert("Not OK");
          return false;
       }
       else
       {
          return true;
       }
    }
    </script>
    Code (markup):
     
    phper, Jul 19, 2006 IP
    donteatchicken likes this.
  3. donteatchicken

    donteatchicken Well-Known Member

    Messages:
    432
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    118
    #3
    Thank alot! I will try this in the morning..
     
    donteatchicken, Jul 19, 2006 IP
  4. donteatchicken

    donteatchicken Well-Known Member

    Messages:
    432
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    118
    #4
    Worked great! just had to add the onChange="mycheck()" to the elements..

    Thanks again..
     
    donteatchicken, Jul 20, 2006 IP
  5. AlphaBillion

    AlphaBillion Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks for this. Very useful
     
    AlphaBillion, Nov 4, 2009 IP