I wish to check if at least one checkbox checked before submission of a form, here is my code:
<script type="text/javascript">
function validate() {
if (document.getElementById('checking').checked) {
alert("checked");
} else {
alert("You didn't check it! Let me check it for you.")
}
}
</script>
<?php foreach (..... ) : ?>
<form name="frm1" id="frm1" method="post" action="next.php" >
...
<input type="checkbox" value="" class="chk" id="checking"/>
...
<a href="#" onclick="$(this).closest('form').submit(); validate();" id="add_view" ><img src="/submit.png"></a>
....
</form>
I did like that but it seems dosn't work for me,I see the message but at the same time it make submission also that not enought to verify atleast one checkbox is checked?