How do I show an alert with Javascript if there are more than 4 checked checkboxes?
I have written the following code however it doesn't work.
var select1 = select = document.getElementById('edit-checkbox');
select1.onchange = function() {
if ($('#edit-checkbox').length > 4) {
alert("Please dont choose more than 4 answers for this question!");
}
<div id="edit-checkbox">
<input type="checkbox" name="rGroup" value="1" id="r1" checked="checked" />
<label class="whatever" for="r1"></label>
<input type="checkbox" name="rGroup" value="2" id="r2" />
<label class="whatever" for="r2"></label>
<input type="checkbox" name="rGroup" value="3" id="r3" />
<label class="whatever" for="r3"></label>
</div>
2- Question: is it possible to disable the rest of the checkboxes dynamically, so that there is no need to show the alert?