Ticking checkboxes - there must be a more elegant way than this?
<p>I have a bunch of related checkboxes, with integer values. I'm trying to encompass the simple logic that:</p>

<ul>
<li>when you tick a box, all the boxes with a value &lt;= should get automatically ticked.</li>
<li>when you untick a box, all the boxes with a value > should get automatically unticked.</li>
</ul>

<p>This is what I've got, which works, but takes up sixteen lines and looks a bit repetitive. Is there a better way?</p>

<pre><code>$('.chk_level').click(function(event){
    var this_val        = parseInt( $(this).val() );
    var this_is_checked = $(this).is(':checked');
    $('.chk_level').each(function(i,chk){
        var $chk = $(chk);
        if ( this_is_checked ){
            if ( parseInt( $chk.val() ) &lt;= this_val ){
                $chk.attr('checked', true);
            }
        }else{
            if ( parseInt( $chk.val() ) &gt; this_val ){
                $chk.attr('checked', false);
            }
        }
    });
});
</code></pre>
