Verifying a form in Javascript
<p>I am working on a php file for school and we have to do some javascript verification of first name, last name and email. If everything is OK we can choose if we want to add the driver or cancel. if something is wrong you go back to the form. I did the verify script in a small page and got it to work there, but when I put it in my php file it will not work anymore. Here are some snippets of the code:</p>

<pre><code>&lt;script type = "text/javascript" &gt;
function val_name()
{
    var namePattern = /^[A-Za-z]{3,25}$/;
    if( !namePattern.test(document.upload.fn.value))
            alert("Enter valid first name");

    if( !namePattern.test(document.upload.ln.value))
        alert("Enter valid last name");

    var x=document.forms["upload"]["email"].value;
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");

    if (atpos &lt; 1 || dotpos &lt; atpos + 2 || dotpos + 2 &gt;= x.length)
    {
        alert("Not a valid e-mail address");
        return false;
    }
    else (confirm("Are you sure you want to add this driver?")== true)
    {
        window.location = 'add_driver.php';
    }
}
&lt;/script&gt;

    &lt;form id="upload" action="&lt;?php echo $_SERVER['php_self'];?&gt;" method="post" enctype="multipart/form-data" onsubmit="val_name()"&gt;

This is part of the html - the email part of it

&lt;td&gt;
email
&lt;/td&gt;
&lt;td&gt;
&lt;input type="text" id="email" name="email"/&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="2" align="center"&gt;
&lt;input type="submit" id="add_driver" name="add_driver" value="add_driver" /&gt;
&lt;input type="reset" value="clear form"/&gt;
</code></pre>
