Below I am trying to ensure that my checkbox and inputs are all filled before allowing user to submit. It ignores my check on the checkbox and opens up the submit after the fields only are filled. What am I doing wrong?
$('#first, #last, #pass').bind('keyup', function() {
if (allFilled()) $('#register').removeAttr('disabled');
});
function allFilled() {
var filled = true;
console.log($('#checkbox').prop('checked'))
$('body input').each(function() {
if ($(this).val() == '' && $('#checkbox').prop('checked') == false) filled = false;
});
return filled
};
html:
<body>
<form>
Username
<br />
<input type="text" id="first" name="first" />
<br /> First
<br />
<input type="text" id="last" name="last" />
<br /> Last
<br />
<input type="text" id="pass" name="pass" />
<br /> Password
<br />
<input type="checkbox" class="checkbox" id="checkbox" name="checkbox" />
<br />
<input type="submit" id="register" disabled value="Register" />
</form>
<div id="test">
</div>
</body>