# False validation still executing code

**URL:** https://forum.kirupa.com/t/false-validation-still-executing-code/266789
**Category:** web dev
**Created:** [July 24, 2008, 11:27am UTC](https://forum.kirupa.com/t/false-validation-still-executing-code/266789 "2008-07-24T11:27:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![korpela2](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@korpela2](https://forum.kirupa.com/u/korpela2)
#### Post date: [July 24, 2008, 11:27am UTC](https://forum.kirupa.com/t/false-validation-still-executing-code/266789/1 "2008-07-24T11:27:48Z")

</div>

I have javascript validating the following form. When the email is not entered an alert box is thrown up stating “not a valid email”. however the action “collectMailPHP.php” is still executed. Can anyone help?

Here is the javascript:

\<script type=“text/javascript”\>

function validate\_email(field,alerttxt)  
{  
with (field)  
{  
apos=value.indexOf("@");  
dotpos=value.lastIndexOf(".");  
if (apos\<1||dotpos-apos\<2)  
{alert(alerttxt);return false;}  
else {return true;}  
}  
}

function validate\_form(thisform)  
{  
with (thisform)  
{  
if (validate\_email(email\_client,“Not a valid e-mail address!”)==false)  
{email.focus();return false;}

}  
}  
\</script\>

Here is the form;

\<form action=“collectMailPHP.php” method=“post” onsubmit=“return validate\_form(this);”\>

\<fieldset\>

\<legend\> \<span class=“style1”\>Find Out More\</span\> \</legend\>  
\<ul\>

```
  &lt;li&gt;  
          
  &lt;input type="text" class="contact_select" onfocus="if (this.value=='-Enter Email Address-'){this.value='';}" onblur="if (this.value==''){this.value='-Enter Email Address-';}" border="2" name="email_client" tabindex="1" value="-Enter Email Address-"&gt;&lt;/li&gt;
  
   &lt;li&gt;  

            &lt;select class="contact_select" name="subject"&gt;
            
            &lt;option&gt;I'm interested in...&lt;/option&gt;
             &lt;option&gt;Bingo Machines&lt;/option&gt;
               &lt;option&gt;Raffle Equipment&lt;/option&gt;
              &lt;option&gt;Arcade Games&lt;/option&gt;
             &lt;option&gt;Electronic Promotions&lt;/option&gt;
             &lt;option&gt;Other products&lt;/option&gt;
            
            
            
            &lt;/select&gt;
        &lt;/li&gt;

```

\<div id=“submit\_2”\>  
\<input type=“submit” border=“1” value=“Submit” tabindex=“5” /\>  
\</div\>

```
  &lt;/ul&gt; 
  &lt;/fieldset&gt;
  
  &lt;/form&gt;
```
