I have following code to check a checkbox when user presses any key. However my requirement is to uncheck the checkbox when the user deletes the text entered by him in the text box. Please suggest how do I do this?
<input type="text" id="search" name="mysearch"
onkeypress="enableCheckBox('search')"/>
<input type="checkBox" id="search_cb"
name="search_cb"/>
function enableCheckBox(id) {
var myCheckbox = document.getElementById(id + "_cb");
if(!myCheckbox.checked) {
myCheckbox.checked = true;
}
}
You might want to rename the function as well since it’s going to check itself if something is typed, but uncheck if the input is empty.