title: Form Displays Input Warning But Still Submits
body: <p>I have a form in which I want users to input data. However, I do not want users to insert certain words. The code I have added recognizes these words and a popup message appears. When the user acknowledges the message, the form submits the data regardless. I've no idea why this happens. The code is listed below.</p>
  <p>HTML Form</p>
  <pre><code>&lt;form name=&quot;form1&quot; action=&quot;#&quot; method=&quot;post&quot; required&gt;
      &lt;label&gt;Line 1:&amp;nbsp; &lt;/label&gt;
      &lt;input type=&quot;text&quot; name=&quot;firstline&quot; required onClick=&quot;select_area()&quot;&gt;&lt;br/&gt;
      &lt;label&gt;Line 2:&amp;nbsp; &lt;/label&gt;
      &lt;input type=&quot;text&quot; name=&quot;secondline&quot; required onClick=&quot;select_area2()&quot;&gt;&lt;br/&gt;
      &lt;label&gt;Line 3:&amp;nbsp; &lt;/label&gt;
      &lt;input type=&quot;text&quot; name=&quot;thirdline&quot; required onClick=&quot;select_area3()&quot;&gt;&lt;br/&gt;
      &lt;input type=&quot;submit&quot; name=&quot;submit_btn&quot; id=&quot;submit&quot; value=&quot;Submit&quot; onClick=&quot;validate_text();&quot;&gt;
      &lt;input type=&quot;reset&quot; id=&quot;reset&quot; value=&quot;Reset&quot;&gt;
  &lt;/form&gt;
  </code></pre>
  <p>JavaScript File</p>
  <pre><code>var swear_words_arr=new Array(&quot;word1&quot;,&quot;word2&quot;,&quot;word3&quot;);
  
  var swear_alert_arr=new Array;
  var swear_alert_count=0;
  function reset_alert_count()
  {
      swear_alert_count=0;
  }
  function validate_text()
  {
      reset_alert_count();
      var compare_text=document.form1.firstline.value;
      for(var i=0; i&lt;swear_words_arr.length; i++) {
          for(var j=0; j&lt;(compare_text.length); j++) {
              if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
              {
                  swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
                  swear_alert_count++;
              }
          }
      }
      
      var compare_text=document.form1.secondline.value;
      for(var i=0; i&lt;swear_words_arr.length; i++) {
          for(var j=0; j&lt;(compare_text.length); j++) {
              if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
              {
                  swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
                  swear_alert_count++;
              }
          }
      }   
      
      var compare_text=document.form1.thirdline.value;
      for(var i=0; i&lt;swear_words_arr.length; i++) {
          for(var j=0; j&lt;(compare_text.length); j++) {
              if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
              {
                  swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
                  swear_alert_count++;
              }
          }
      }
      
      var alert_text=&quot;&quot;;
      for(var k=1; k&lt;=swear_alert_count; k++){
          alert_text+=&quot;\n&quot; + &quot;(&quot; + k + &quot;)  &quot; + swear_alert_arr[k-1];
      }
      if(swear_alert_count&gt;0) {
          alert(&quot;The message will not be sent!!!\nThe following illegal words were found:\n_______________________________\n&quot; + alert_text + &quot;\n_______________________________&quot;);
          document.form1.text.select();
      } else {
          document.form1.submit();
      }
  }
  
  function select_area()
  {
      document.form1.firstline.select();
  }
      
  function select_area2()
  {
      document.form1.secondline.select();
  }
      
  function select_area3()
  {
      document.form1.thirdline.select();
  }
      
  window.onload=reset_alert_count;
  </code></pre>