Reputation: 83
Hi im trying to make that my checkbox checked when the user type 8 digits on my input textbox. Now i can make the checkbox checked when te user types but im new in this and can't figure it out. THX for the help.
<input id="thecheckbox" type="checkbox">
<input id="theinput" type="text">
$("#theinput").keyup(function () {
if ($(this).val() == "") {
$("#thecheckbox").prop("checked", false);
} else {
$("#thecheckbox").prop("checked", true);
}
});
$("#thecheckbox").change(function () {
if (!$(this).is(':checked')) {
$("#theinput").val("");
}
});
Upvotes: 0
Views: 66
Reputation: 78520
Do you mean something like this?
$("#theinput").on('input', function () {
if (this.value.length >= 8) {
$("#thecheckbox").prop("checked", true);
} else {
$("#thecheckbox").prop("checked", false);
}
});
/* $("#thecheckbox").change(function () {
if (!$(this).is(':checked')) {
$("#theinput").val("");
}
}); */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="thecheckbox" type="checkbox">
<input id="theinput" type="text">
Upvotes: 1