title: Javascript - Validate form if error found change form field background color to red
body: <p>Ive got a form, when the user clicks on a field the value clears, when the user clicks submit, AND an error is found the background color of the field should change to red.</p>
  
  <p><strong>My problem</strong> </p>
  
  <p>I manage to  clear the value of the field when a user clicks it, and I managed to change the  color of the field to red when an error is found, BUT when the error is found when the user clicks submit <strong>the background color only change to red for a split second and then the field value reapers again.</strong>  Ive been battling away with this for the whole morning any help would be appreciated, code follows:</p>
  
  <pre><code>function validate(){
      //form validation
      var name=document.getElementById('name');
       if (name.value == null || name.value==""){
         name.style.backgroundColor="red";
       }  
  
  &lt;form id="enquire" method="post"&gt;
      &lt;h2&gt;Test Drive an Audi Today&lt;/h2&gt;
      &lt;input type="text"  value="Name" class="textbox" id="name" name="name" onclick="if(this.value=='Name') this.value='';" /&gt;&lt;br /&gt;
  
  
  &lt;input type="submit" name="submit" class="butt" value="Send" onclick="validate()"  /&gt;
         &lt;span class="buttonText"&gt;We'll Call you Back!&lt;/span&gt;
      &lt;/form&gt;
  </code></pre>