Web Analytics Made Easy -
StatCounter resetting specified checkboxes - CodingForum

Announcement

Collapse
No announcement yet.

resetting specified checkboxes

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

  • resetting specified checkboxes

    Alright I'm having problems with resetting specific checkboxes.
    I have like so:
    Code:
    <input type="checkbox" name="defcheck" value="yes" CHECKED>
    <input type="checkbox" name="checkbox[]" value="1">
    <input type="checkbox" name="checkbox[]" value="2" CHECKED>
    <input type="checkbox" name="checkbox[]" value="3">
    <input type="checkbox" name="checkbox[]" value="4" CHECKED>
    So heres what I'm trying to do. Its set so when you check on any check box, it will automatically uncheck the defcheck box. What I want it to do, is when you once again check on the defcheck, it will automatically reset the remainder of the checkboxes back to their original values. Any suggestions?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #2
    Is this enough?
    Code:
    function resetBoxes(obj){
      if (obj.checked){
        var chks = obj.form.elements['checkbox[]'];
        for (var j=0;j<chks.length;j++){
          chks[j].checked = (chks[j].defaultChecked) ? true:false;
        }
      }
    }
    ...
    <input type="checkbox" name="defcheck" value="yes" onclick="resetBoxes(this)" CHECKED>
    <input type="checkbox" name="checkbox[]" value="1" onclick="this.form.defcheck.checked=false">
    <input type="checkbox" name="checkbox[]" value="2" onclick="this.form.defcheck.checked=false" CHECKED>
    <input type="checkbox" name="checkbox[]" value="3" onclick="this.form.defcheck.checked=false">
    <input type="checkbox" name="checkbox[]" value="4" onclick="this.form.defcheck.checked=false" CHECKED>
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Yeah, just some minor alterations to match, works great!
      Thanx glenngv!
      BTW, how does that ? true:false work? I mean, what would that be telling the js to do?
      PHP Code:
      header('HTTP/1.1 420 Enhance Your Calm'); 
      Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

      Comment


      • #4
        It's an if statement

        same as:
        Code:
        if (chks[j].defaultChecked)
        {
        chks[j].checked = true;
        }
        else
        {
        chks[j].checked = false;
        }
        It's the same, but shorter...
        Shawn

        Comment


        • #5
          Correct!

          That is called a ternary operator, which can be thought of as a shortcut to an if-else statement.
          Glenn
          vBulletin Mods That Rock!

          Comment

          Working...
          X