Glen Lipka wrote:
> 
> I have 4 checkboxes vertical
> 
> <input type="checkbox"><label>box 1</label><br />   <input
> type="checkbox"><label>box 1 and 2</label><br />   <input
> type="checkbox"><label>box 1 and 2 and 3</label><br /> <input
> type="checkbox"><label>box 1 and 2 and 3 and 4</label><br />
> 
> When I click one, I want to check the boxes of all the ones previous to it
> (including it).  And uncheck all the boxes after it.
> 
I thought about an approach that checked all the boxes then cleared the ones
following the checked one by using selectors and DOM navigation, but I think
it's much simpler to do an each() instead. 

$(document).ready(function(){
  $("#myform checkbox").bind("click", function(){
    var mybox = this;
    var tick = true;
    $("myform checkbox").each(function(){
      this.checked = tick;
      if ( this == mybox )
        tick = false;
    });
  });
});
-- 
View this message in context: 
http://www.nabble.com/Checkbox%3A-Selecting-all-Previous-tf2715371.html#a7572127
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to