I have 3 checkboxes with the following jQuery and it works great.
$(document).ready(function() {
var $finishBoxes = $('#co1,#co2,#co3');
$finishBoxes.change(function(){
// check if all are checked based on if the number of checkboxes total
// is equal to the number of checkboxes checked
if ($finishBoxes.length == $finishBoxes.filter(':checked').length) {
$('#submit2pd').attr("disabled", false);
}
else{
$('#submit2pd').attr("disabled", true);
}
});
$finishBoxes.ready(function(){
// check if all are checked based on if the number of checkboxes total
// is equal to the number of checkboxes checked
if ($finishBoxes.length == $finishBoxes.filter(':checked').length) {
$('#submit2pd').attr("disabled", false);
}
else{
$('#submit2pd').attr("disabled", true);
}
});
});
I want to add the following select option to the if statement so if all 3 are checked and the checkbox value=1 (yes) then the $(‘#submit2pd’).attr(“disabled”, true);
<select name="tcaccept" id="tcaccept">
<option value="0"<?php if($mychecklist->tcaccept==0) echo 'selected' ?>>No</option>
<option value="1"<?php if($mychecklist->tcaccept==1) echo 'selected' ?>>Yes</option>
</select>
Any help would be greatly appreciated.
Here some proper code:
If you are using jquery 1.6+, it’s better to use .prop() for special attributes like disabled (or checked …).
Edit according to the comments:
To cancel the form submition, simply
return false;:I’ve created a jsfiddle for you to play with.