title: JavaScript validation change value on submit
body: <p>I need to set a form input value to -1 when submitted if nothing is entered. 
  So far I have this function, but it doesn’t change the value to -1.</p>
  
  <pre><code>&lt;form action="validate.php"
        method="post" onsubmit="return validate()" &gt;
  
  &lt;input type="text" name="CategoryID" size="3" maxlength="3" onkeyup="checkCategoryID(this)"/&gt;
  
  function validate()
  {
      var catID;
      catID = document.getElementsByName("CategoryID");
  
      if (catID.value == "")
          catID.value = -1;
      return true;
  
  }
  </code></pre>