title: Setting focus to input element on validation error not working
body: <p>I have a long list of input fields created from data in a database, more or less like this:</p>
  
  <pre><code>foreach ($data as $value) { 
  ...
  
  &lt;input type="text" name="date_earned$row" id="date_earned$row" value = "$date_earned" onchange="changeDate(this)"&gt;
  ...
  }
  </code></pre>
  
  <p>The onchange script is like this (note: the date is not a standard date so I'm not trying to validate a normal date).  It won't let me set focus back to the element that I just changed, if there is an error.  I have no trouble setting the focus to a different element.  Why?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function changeDate(sel) {
    var theDate = sel.value;
    var isValid = true;
    if (theDate) {
   &lt;!-- .... some stuff in here to validate the date, sets isValid = false if it is not correct format} --&gt;
  }
  
   if (!(isValid)) {
  &lt;!--    ... do some stuff in here to display the error message --&gt;
    document.getElementById('thiselementsid').focus(); &lt;!-- this doesn't work when 'thiselementsid' is the id of the element which just lost focus--&gt;
    document.getElementById('someotherelement').focus(); &lt;!-- this works, but not if 'someotherelement' is the id of the last focused element --&gt;
  </code></pre>
  
  <p>}
  </p>