title: Change an element's onfocus handler with Javascript?
body: <p>I have a form that has default values describing what should go into the field (replacing a label). When the user focuses a field this function is called:</p>
  
  <pre><code>function clear_input(element)
  {
      element.value = "";
      element.onfocus = null;
  }
  </code></pre>
  
  <p>The onfocus is set to null so that if the user puts something in the field and decides to change it, their input is not erased (so it is only erased once). Now, if the user moves on to the next field without entering any data, then the default value is restored with this function (called onblur):</p>
  
  <pre><code>function restore_default(element)
  {
      if(element.value == '')
      {
          element.value = element.name.substring(0, 1).toUpperCase()
                            + element.name.substring(1, element.name.length);
      }
  }
  </code></pre>
  
  <p>It just so happened that the default values were the names of the elements so instead of adding an ID, I just manipulated the name property. The problem is that if they do skip over the element then the onfocus event is nullified with clear_input but then never restored.</p>
  
  <p>I added</p>
  
  <pre><code>element.onfocus = "javascript:clear_input(this);";
  </code></pre>
  
  <p>In restore_default function but that doesn't work. How do I do this?</p>