View Full Version : uncheck and check when other filled in

09-08-2008, 06:12 PM
I have

<input type="checkbox" name="item" value="11" id="id11">
<input name="other" type="text">

How can I make it that when someone fills in the other text box the checkbox gets checked and when they delete from the other textbox the checkbox gets unchecked.

Philip M
09-08-2008, 06:48 PM
<input type="checkbox" name="id11" id="id11" value="11" >
<input name="other" id = "other" type="text" onblur = "chk()">

<script type = "text/javascript">
function chk() {
var x = document.getElementById("other").value;
x = x.replace(/^\s+/,""); // strip leading spaces
document.getElementById("other").value = x;
if (x.length > 0) {
document.getElementById("id11").checked = true;
else {
document.getElementById("id11").checked = false;
We are sorry that as a result of a typographical error we referred to General X as "a bottle-scarred old veteran".
This should of course have read "a battle-scared old veteran".