I'm trying to do a simple validate on my page with jquery. The top 'var a to e' values work fine but I have an issue with check boxes (var fa to ff) which must have at least one checked before the page submits. I've tried is checked, prop and bog-standard val (with true/false, 0, isnull etc) but all allow the page to be submitted rather than throwing up the #edialog message.
Can anyone see where I've gone wrong? Thanks in advance!
<script>
function validateForm() {
var a = $('#Name').val();
var b = $('#Ward').val();
var c = $('#Job').val();
var d = $('#LDate').val();
var e = $('#Reason').val();
var fa = $('#MCHFT').prop('checked');
var fb = $('#ONHS').prop('checked');
var fc = $('#PSEC').prop('checked');
var fd = $('#PUBSEC').prop('checked');
var fe = $('#EDU').prop('checked');
var ff = $('#NEMP').prop('checked');
if (a == null || a == "") {
$('#EC1').show();
$('#edialog').dialog('open');
return false;
}
if (b == null || b == "") {
$('#EC2').show();
$('#edialog').dialog('open');
return false;
}
if (c == null || c == "") {
$('#EC3').show();
$('#edialog').dialog('open');
return false;
}
if (d == null || d == "") {
$('#EC4').show();
$('#edialog').dialog('open');
return false;
}
if (e == null || e == "") {
$('#EC5').show();
$('#edialog').dialog('open');
return false;
}
if (fa === "false" & fb === "false" || fb === "false" || fc === "false" || fd === "false" || fe === "false" || ff == "false") {
$('#EC8').show();
$('#edialog').dialog('open');
return false;
}
}
</script>
Edit: I just noticed a an error and thanks to the pointers i've updated my code so that the f vars look like this (as it should be && rather than || i think) but it still does not work - any more ideas?:
if (fa === false && fb === false && fb === false && fc === false && fd === false && fe === false && ff == false) {
$('#EC8').show();
$('#edialog').dialog('open');
return false;
}
I've created a JSFiddle (no working at all - i'm new to this!) here: http://jsfiddle.net/f5nwv4by/