title: Trouble using JavaScript events on submitting a form to validate its fields
body: <p>I would like to implement a form with fields for which the validation is "real-time" using JavaScript. </p>
  
  <p>In order to do that I used Java events in this way:</p>
  
  <p><strong>Text field</strong></p>
  
  <p><em>onkeyup</em>: this is used to send a request that checks if there are errors for this field every time you release a key. If there are errors it will show those, otherwise an "Ok!" text. </p>
  
  <p><strong>Submit button</strong></p>
  
  <p><em>onclick</em>:  when clicked, this will check <em>again</em> if there are errors. If so, this will show errors, otherwise it will hide the submit button.</p>
  
  <p>At the end of the page I have a JavaScript that will <em>focus</em> a Text Field when show up.</p>
  
  <p>Using simultaneously <em>onkeyup</em> and <em>focus</em> events on the field, after the form is submitted WITHOUT click the button (event related to the button happens only when the button is clicked, not when I use the 'enter' key [on keyboard] to submit the form), the <em>focus</em> event will trigger automatically the <em>onkeyup</em> event: this means that, after submitting, are called two events (<em>focus</em> implies <em>onkeyup</em>) and so for the Text Field will be displayed first the errors, if there are, and then the "Ok!" text.</p>
  
  <p><strong>I would like to not <em>focus</em> on the field after submitting the form so the <em>onkeyup</em> event will be not triggered... or use the 'enter' key to simulate the 'click' of the submit button.</strong></p>
  
  <hr>
  
  <p>P.S.: if you know other techniques to perform validation in "real-time" (and better), let me know.</p>