<div class="max5">
<input type="checkbox" id="Checkbox0" />
<input type="checkbox" id="Checkbox1" />
<input type="checkbox" id="Checkbox2" />
<input type="checkbox" id="Checkbox3" />
<input type="checkbox" id="Checkbox4" />
<input type="checkbox" id="Checkbox5" />
<input type="checkbox" id="Checkbox6" />
<input type="checkbox" id="Checkbox7" />
</div>
<script type="text/javascript" src="
http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript">
$(document).ready(function(){
var i = 0;
$(".max5 input[type=checkbox]").each(function(){
$(this).click(function(){
$(this).removeAttr('index');
if($(this).is(':checked'))
{
$(this).attr('index', i++);
}
y = 5000;
var elm;
if($(".max5 input[index]").length > 5)
{
$(".max5 input[index]").each(function(){
if(y > $(this).attr('index'))
{
y = $(this).attr('index');
elm = $(this);
}
});
$(elm).removeAttr('index');
$(elm).removeAttr('checked');
}
});
});
});
</script>