dimanche 5 novembre 2017

JS - Enable/Disable textarea with checkbox

Basically, my task is to use JavaScript to enable the when the checkbox is clicked (on) and disable it when it is clicked (off). However, the code still isn't working, and won't do anything regardless of whether I click the checkbox or not.

</head>
<body>
<div id="container">
<h2> Order Information </h2>
<div class="entry">
  Select color:
  <select name="color">
    <option selected="selected">White</option>
    <option>Black</option>
    <option>Red</option>
    <option>Green</option>
    <option>Blue</option>
  </select> <br><br>
  Select shirt size:
  <select name="sizeandprice">
    <option>Small - $9.99</option>
    <option>Medium - $10.99</option>
    <option selected="selected">Large - $11.99</option>
    <option>X-Large - $13.99</option>
  </select><br><br>
  Is this a gift? <input type="checkbox" name="gift"> <br><br>
  Write your gift message here: <br>
  <textarea disabled rows="5" cols="50" name="message">Type your message here.
  </textarea>
</div>
</div>

</body>
</html>

Here's the Javascript code:

function enable(x) {
    x = document.getElementbyId("gift");
    x.checked
    if(x == true) {
        var textarea = document.getElementbyId("message");
        textarea.disabled = false;
    }
    else {
        var textarea = document.getElementbyId("message");
        textarea.disabled = true;
    }

}




Aucun commentaire:

Enregistrer un commentaire