title: Form Validation is not Working
body: <p>Form validation not working due to using value="" attribute in form.
  Can anyone please suggest me any way to validating form with current validation code with using value="" attribute in form.</p>
  
  <p>HTML Code-</p>
  
  <pre><code>&lt;form action="email.php" method="post" name="contactForm" id="contactForm" onsubmit="return validateForm();"&gt;
      &lt;input type="text" onfocus="if(this.value == 'Name'){this.value = '';}" onblur="if(this.value == ''){this.value='Name';}" id="Name" value="Name" name="name"&gt;
      &lt;input type="text" onfocus="if(this.value == 'Company'){this.value = '';}" onblur="if(this.value == ''){this.value='Company';}" id="Company" value="Company" name="company"&gt;
      &lt;input type="text" onfocus="if(this.value == 'Email'){this.value = '';}" onblur="if(this.value == ''){this.value='Email';}" id="Email" value="Email" name="email"&gt;
      &lt;input type="text" onfocus="if(this.value == 'Phone'){this.value = '';}" onblur="if(this.value == ''){this.value='Phone';}" id="Phone" value="Phone" name="phone"&gt;                        
  
      &lt;span&gt;
          &lt;input type="text" onfocus="if(this.value == 'Geo Targeting'){this.value = '';}" onblur="if(this.value == ''){this.value='Geo Targeting';}" id="GeoTargeting" value="Geo Targeting" name="geo_targeting"&gt;
          &lt;input type="text" onfocus="if(this.value == 'Web Site'){this.value = '';}" onblur="if(this.value == ''){this.value='Web Site';}" id="WebSite" value="Web Site" name="website"&gt;        
          &lt;textarea onfocus="if(this.value == 'Message'){this.value = '';}" onblur="if(this.value == ''){this.value='Message';}" id="Message" name="message"&gt;Message&lt;/textarea&gt;
          &lt;input class="sendBtn" name="submit" type="submit" value="Send" /&gt;
      &lt;/span&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Javascript Code-</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
      function validateForm() {
          var x=document.forms["contactForm"]["name"].value;
          if (x==null || x=="") {
              alert("Name must be filled out");
              return false;
          }
  
          var x=document.forms["contactForm"]["company"].value;
          if (x==null || x=="") {
              alert("Company Name must be filled out");
              return false;
          }
  
          var x=document.forms["contactForm"]["email"].value;
          var atpos=x.indexOf("@");
          var dotpos=x.lastIndexOf(".");
          if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=x.length) {
              alert("Email must be filled out/Not a valid e-mail address");
              return false;
          }
  
          var x=document.forms["contactForm"]["message"].value;
          if (x==null || x=="") {
              alert("Message must be filled out");
              return false;
          } 
      }
  &lt;/script&gt;
  </code></pre>