Ejemplo cortito pero ilustrativo:
Código PHP:
Ver original<?php
if(@$_POST){
$checkbox_recibidos = count($_POST['ck']); if($checkbox_recibidos > 5){
echo "selecciono mas de 5";
// codigo de retorno
}else{
echo "seleccion igual o menor a 5";
// codigo de redireccion
}
}
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function(){
var max = 5;
var checkboxes = $('input[type="checkbox"]');
checkboxes.change(function(){
var current = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', current >= max);
});
});
</script>
</head>
<body>
<form name="test" id="test" action="" method="post">
<input type="checkbox" name="ck[]" value="1">1
<input type="checkbox" name="ck[]" value="2">2
<input type="checkbox" name="ck[]" value="3">3
<input type="checkbox" name="ck[]" value="4">4
<input type="checkbox" name="ck[]" value="5">5
<input type="checkbox" name="ck[]" value="6">6
<input type="checkbox" name="ck[]" value="7">7
<input type="checkbox" name="ck[]" value="8">8
<input type="checkbox" name="ck[]" value="9">9
<input type="submit" value="enviar" />
</form>
</body>
</html>