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:

<script type = "text/javascript" >
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 < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length)
alert("Not a valid e-mail address");
return false;

(confirm("Are you sure you want to add this driver?")== true)
window.location = 'add_driver.php';

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

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

<input type="text" id="email" name="email"/>
<td colspan="2" align="center">
<input type="submit" id="add_driver" name="add_driver" value="add_driver" />
<input type="reset" value="clear form"/>