...

View Full Version : uncheck and check when other filled in



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

<input type="checkbox" name="item" value="11" id="id11">
and
<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;
}
}
</script>
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".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum