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 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    Enable disabled checkbox via select list

    Hi all. With the below test form I'm trying to enable the checkbox only when the user select the "CLOSED" option from the select box. Initially when the form loads the checkbox ihas a onClick=\"return false\" event. How can I do this??

    Code:
    <form method="POST" name="theForm" action="--WEBBOT-SELF--">
     
      <p><input type="checkbox" onClick="return false" name="TEST"></p>
      <p><select name="STATUS">
        <option value="ACTIVE">ACTIVE</option>
        <option value="CLOSED">CLOSED</option>
      </select></p>
    
      <p><input type="submit" value="Submit" name="B1"></p>
    </form>
    Last edited by nikko50; 09-04-2008 at 04:15 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Here you are, Tracy:-

    Code:
    <form method="POST" name="theForm" action="--WEBBOT-SELF--">
     
      <p><input type="checkbox" name="TEST" disabled></p>
      <p><select name="STATUS" onchange = "fixTest()">
        <option value="ACTIVE">ACTIVE</option>
        <option value="CLOSED">CLOSED</option>
      </select></p>
    
    <p><input type="submit" value="Submit" name="B1"></p>
    </form>
    
    <script type = "text/javascript">
    function fixTest() {
    x = document.theForm.STATUS.value;
    if (x == "CLOSED") {
    document.theForm.TEST.disabled = false;
    }
    else {   // if user switches back to ACTIVE
    document.theForm.TEST.checked= false;
    document.theForm.TEST.disabled = true;
    }
    }
    </script>
    Did you receive the PM I sent you a while back?


    A single parent would only be able to claim benefits for two years, and after those two years they would be literally pushed over the cliff - Politician
    Last edited by Philip M; 09-04-2008 at 08:15 AM.

  • #3
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    Works great and you remembered my name also!

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by nikko50 View Post
    Works great and you remembered my name also!
    Well, I do tend to remember the names of people who have a great many posts (all requesting assistance) but zero thanks.


  •  

    Posting Permissions

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