title: JavaScript. Uncaught ReferenceError: (object) is not defined at HTMLInputElement.onchange
body: <p>I'm trying to develop a web app where all the inputs are "disabled" and will only be enabled when the user is 18+. But the following error is happening:</p>
  
  <p>Uncaught ReferenceError: check is not defined at HTMLInputElement.onchange.</p>
  
  <p>Help me pls!!</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 check(){
   var age = document.getElementById("age").value;
    if (age &gt;= 18) {
     document.getElementById ("city").disabled =false;
     document.getElementById ("state").disabled =false;
     document.getElementById ("country").disabled =false;
     document.getElementById ("submit").disabled =false;
  
   } else{
    document.getElementById ("city").disabled =true;
    document.getElementById ("state").disabled =true;
    document.getElementById ("country").disabled =true;
    document.getElementById ("submit").disabled =true;
   }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>html {
  font-family: "Segoe UI", "Helvetica Neue", Verdana, Arial, sans-serif;
  font-size: 16px;
  height: 95%;
  }
  
  label, input {
  padding: .5rem;
  margin: 1rem;
  }
  
  input[type=text]:enabled {
  background: #ffff00;
  }
  
  input[type='text']:disabled {
  background: #E01E1E;
  }
  
  input[type="text"]:disabled::placeholder {
  color: white;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
   &lt;head&gt;
    &lt;link rel="stylesheet" type="text/css" href="TW-LAB- Pratica11exe14.css"&gt;
    &lt;script type="text/javascript" href="TW-LAB- Pratica11exe14.js"&gt;&lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
    &lt;label&gt;Name: &lt;input type="text" placeholder="name"&gt;&lt;/label&gt;&lt;br&gt;
    &lt;label&gt;Age: &lt;input type="number" placeholder="age" onchange="check()" id="age"&gt;&lt;/label&gt;&lt;br&gt;
    &lt;label&gt;City: &lt;input type="text"  disabled="disabled" placeholder="city" id="city"&gt;&lt;/label&gt;&lt;br&gt;
    &lt;label&gt;State: &lt;input type="text" disabled="disabled" value="state" id="state"&gt;&lt;/label&gt;&lt;br&gt;
    &lt;label&gt;Country: &lt;input type="text" disabled="disabled" placeholder="Country" id="country"&gt;&lt;/label&gt;&lt;br&gt;
    &lt;input type="submit" value="Ok" disabled="disabled" id="submit"&gt;
   &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>