JavaScript: Auto-Tick Checkbox (Real-Time)
by MythOfEchelon
HTML
<!DOCTYPE html> <!-- This is just my basic HTML5 template. Make sure you set this up correctly for your personal needs -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
div {
float: left;
}
#wrapper {
width: 200px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="numberPlate_Wrapper">
<span>Number Plate: </span>
<input type="text" id="numberPlate" onInput="textBox()" />
</div>
<div id="noNumberPlate_Wrapper">
<span>No Number Plate: </span>
<input type="checkbox" id="noNumberPlate" onClick="checkBox()" />
</div>
</div>
<script type="text/javascript">
window.onload = initAll();
function initAll(){
numberPlate = document.getElementById("numberPlate");
noNumberPlate = document.getElementById("noNumberPlate");
textBox();
checkBox();
}
function textBox(){
if ((!numberPlate.value)){
noNumberPlate.checked = true;
} else {
noNumberPlate.checked = false;
}
}
function checkBox(){
if ((numberPlate.value) && (noNumberPlate.checked == false)){
numberPlate.value = "";
}
}
</script>
</body>
</html>