Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts

    uncheck and check when other filled in

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Code:
    <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".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •