title: Disable Button Until Fields are Full Pure JS
body: <p>Trying to keep a button disabled until the form fields are filled in and I cannot seem to accomplish this. I've created a small example with a single field but the principle will be the same with a larger form.</p>
  
  <p>Can anyone help?</p>
  
  <p>Code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function checkForm() {
    var name = document.getElementById("name").value;
    var cansubmit = true;
  
    if (name.value.length == 0) {
      cansubmit = false;
    }
  
    if (cansubmit == false) {
      document.getElementById("submitbutton").disabled = true;
    }
  
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" id="name" onkeyup="checkForm()" /&gt;
  
  &lt;button type="button" id="myButton"&gt;Test me&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>