title: Javascript form validator conflict with math CAPTCHA
body: <p>Here is a basic email form with math Captcha. Captcha is working, but the form validator is not. When I say form validator, I am referring to the required "Name" and "Email" fields. If I remove the Captcha code, the form validator works fine. I think the js code for form validator and js code for Captcha are conflicting with each other somehow.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;EiP - Contact Us&lt;/title&gt;
  
  &lt;script type="text/javascript"&gt;
  // Form validator for the required Name and Email fields
  function MM_validateForm() { //v4.0
    if (document.getElementById){
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i&lt;(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p&lt;1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num&lt;min || max&lt;num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
  } }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;  
      &lt;p&gt;Do you have a question or comment about EiP? We want to hear from you as your feedback is critical to our success.&lt;/p&gt;
      &lt;p class="required"&gt;*Required info&lt;/p&gt;
      &lt;form action="contactus.html" method="post" name="contactform" id="contactform" onsubmit="return checkform(this);MM_validateForm('name','','R','email','','RisEmail');return document.MM_returnValue"&gt;
      &lt;p class="allforms"&gt;Full Name&lt;span&gt;*&lt;/span&gt;&lt;/p&gt;
      &lt;input name="name" type="text"  id="name"/&gt;                        
      &lt;p class="allformsRt"&gt;Email Address&lt;span&gt;*&lt;/span&gt;&lt;/p&gt;
      &lt;input type="text" name="email" id="email" /&gt;
      &lt;p class="allforms"&gt;Company&lt;/p&gt;
      &lt;input name="company" type="text"  id="company" /&gt;
      &lt;p class="allformsRt"&gt;Phone Number&lt;/p&gt;
      &lt;input type="text" name="phone" id="phone" /&gt;
      &lt;p class="allforms"&gt;How can we help?&lt;/p&gt;
      &lt;textarea name="application" cols="35" rows="5" title="title" label="label" style="float:left"&gt;Type your questions, comments, feedback&lt;/textarea&gt;
      &lt;label for="code" style="float:left; clear:both"&gt;Write code below &gt; &lt;span id="txtCaptchaDiv" style="color:#F00"&gt;&lt;/span&gt;&lt;!-- this is where the script will place the generated code --&gt; 
      &lt;input type="hidden" id="txtCaptcha" /&gt;&lt;/label&gt;&lt;!-- this is where the script will place a copy of the code for validation: this is a hidden field --&gt;
      &lt;input type="text" name="txtInput" id="txtInput" size="30" style="float:left; clear:both" /&gt; 
      &lt;input name="Submit" type="submit" value="Contact Us" style="float:left; clear:both" /&gt;
          &lt;/form&gt;
  
  &lt;script type="text/javascript"&gt;
  //Generates the captcha function    
      var a = Math.ceil(Math.random() * 9)+ '';
      var b = Math.ceil(Math.random() * 9)+ '';       
      var c = Math.ceil(Math.random() * 9)+ '';  
      var d = Math.ceil(Math.random() * 9)+ '';  
      var e = Math.ceil(Math.random() * 9)+ '';  
  
      var code = a + b + c + d + e;
      document.getElementById("txtCaptcha").value = code;
      document.getElementById("txtCaptchaDiv").innerHTML = code;  
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  function checkform(theform){
      var why = "";
  
      if(theform.txtInput.value == ""){
          why += "- Security code should not be empty.\n";
      }
      if(theform.txtInput.value != ""){
          if(ValidCaptcha(theform.txtInput.value) == false){
              why += "- Security code did not match.\n";
          }
      }
      if(why != ""){
          alert(why);
          return false;
      }
  }
  
  // Validate the Entered input aganist the generated security code function   
  function ValidCaptcha(){
      var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
      var str2 = removeSpaces(document.getElementById('txtInput').value);
      if (str1 == str2){
          return true;    
      }else{
          return false;
      }
  }
  
  // Remove the spaces from the entered and generated code
  function removeSpaces(string){
      return string.split(' ').join('');
  }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>