The purpose is to check whether the two fields (username and password) have text entered, if so, check the checkbox, if not, uncheck the checkbox.
It works if I enter text in both. It unchecks if I delete the text in the user field; however, if I reenter a character in the user field, the box will not recheck. What could be happening?
<div class="controls">
@Html.CheckBoxFor(model => model.checkboxId, new Dictionary<string, object> { { "disabled", "disabled" } })
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#Username, #Password').change(function () {
var username = $('input#Username').val();
var password = $('input#Password').val();
if (username.length != 0 && password.length != 0) {
$('#checkboxId').attr('checked', true);
}
else {
$('#checkboxId').removeAttr('checked');
}
});
</script>