title: Need JavaScript validation and submission
body: <p>I have done certain amount of validation but cannot stop the form from submitting it. Please help me with the validation of other left fields. This is my code:</p>
  <pre><code>&lt;form action=&quot;&quot; method=&quot;post&quot; id=&quot;contacts-form&quot; onsubmit=&quot;return &gt;
  &lt;fieldset&gt;
  &lt;div class=&quot;field&quot;&gt;
  &lt;input type=&quot;text&quot; value=&quot;Name:&quot; id=&quot;name&quot; onfocus=&quot;if(this.value=='Name:'){this.value=''}&quot; onblur=&quot;if(this.value==''){this.value='Name:'}&quot; /&gt;`enter code here`
  &lt;/div&gt;
  &lt;div class=&quot;field&quot;&gt;
  &lt;input type=&quot;text&quot; value=&quot;E-mail:&quot; id=&quot;email&quot; onfocus=&quot;if(this.value=='E-mail:'){this.value=''}&quot; onblur=&quot;if(this.value==''){this.value='E-mail:'}&quot; /&gt;
  &lt;/div&gt;
  &lt;div&gt;
  &lt;textarea cols=&quot;1&quot; rows=&quot;1&quot; id=&quot;message&quot; onfocus=&quot;if(this.value=='Message:'){this.value=''}&quot; onblur=&quot;if(this.value==''){this.value='Message:'}&quot;&gt;Message:&lt;/textarea&gt;
  &lt;/div&gt;
  &lt;div class=&quot;link&quot;&gt;&lt;a href=&quot;#&quot; onclick=&quot;document.getElementById('contacts-form').reset()&quot;&gt;Clear&lt;/a&gt; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;#&quot; onclick=&quot;document.getElementById('contacts-form').submit(validateForm();)&quot;&gt;Send&lt;/a&gt;&lt;/div&gt;'
  </code></pre>
  <p><strong>The Js code I used is this:</strong></p>
  <pre><code>function validateForm()
  {
  var x=document.forms[&quot;contacts-form&quot;][&quot;email&quot;].value;
  var atpos=x.indexOf(&quot;@&quot;);
  var dotpos=x.lastIndexOf(&quot;.&quot;);
  
  if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=x.length)
  {
  alert(&quot;Not a valid e-mail address&quot;);
  return false;
  }
  }
  </code></pre>