title: How do I check and change the value of an input with using javascript
body: <p>If user types in a value more than 5, I want to set it to 5. </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 maxValCheck() {
    if (document.getElementById('xxx').value &gt; 5) {
      document.getElementById('xxx').value = 5;
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input id="xxx" type="number" onkeypress="maxValCheck()" max="5" min="1" value="1" /&gt;</code></pre>
  </div>
  </div>
  </p>