Onsubmit function not working
<p>My onsubmit function is not working.</p>

<p>My PHP file has two forms. Both form tags have an onsubmit attribute that links to the same javascript file. The first form's onsubmit is working. The function being called by the second form has been simplified to this:</p>

<pre><code>function UserDataCheck()
{
   return false;
}
</code></pre>

<p>The form tag is </p>

<pre><code>form name='user_form' method='post' onsubmit='return UserDataCheck();'
</code></pre>

<p>This tag is enclosed within &lt;> and double quotes and echo-ed out in a PHP file. </p>

<p>Please help. This is driving me crazy! Earlier I was doing some data checking in the UserDataCheck() but I stripped all of that away to see if I could even use onsubmit to stop the user from submitting! NO SUCCESS.</p>

<p>Here's more code!</p>

<pre><code> echo "&lt;html&gt;"; 
    echo "&lt;head&gt;"; 
    echo "&lt;title&gt;Survey Form&lt;/title&gt;"; 
    echo "&lt;link link rel='stylesheet' href='examples.css' type='text/css'&gt;"; 
    echo "&lt;/head&gt;";
echo "&lt;script src='validation.js'&gt;&lt;/script&gt;"; 
echo "&lt;body topmargin='20', leftmargin='20', rightmargin='20', style='background-color:beige; font-family:calibri;'&gt;"; 
echo "&lt;img src='CSE Global.jpg' width='250' height='70' align='right' /&gt;";
//--------------------------------------------------------------------- 
// Firstly, we determine who is using this system 
// Check $_GET['dex'] for a value, if provided, then it's the user 
// if not, then it's the administrator (see my notes below the code for 
// more info) 
//--------------------------------------------------------------------- 

"&lt;input type='text' name='dex' length='50'&gt;";
"&lt;input type='boolean' name='sub' length='1'&gt;";
if ($_GET['dex']=="") {  
    //--------------------------------------------------------------------- 
    // $_GET['dex'] is empty so we can presume this is the Admin 
    //--------------------------------------------------------------------- 
    echo "&lt;p style='font-family:cambria;font-size:35px;'&gt; WELCOME ADMIN!&lt;/p&gt;"; 


    //--------------------------------------------------------------------- 
    // We now check to see if the form has been submitted or not ... 
    // To do this, we check if the variable 'sub' is in the $_POST array 
    //--------------------------------------------------------------------- 
    if ($_POST['sub']!=1) { 
        //--------------------------------------------------------------------- 
        // The form has not been submitted already so present the "admin form" 
        //---------------------------------------------------------------------


// check that they entered an amount tested, an amount passed,
// and that they didn't pass units than they more than tested



        echo "&lt;form name='admin_form' method='post' onsubmit='if(!AdminDataCheck()) return      false;'&gt;"; 
        echo "&lt;p&gt;&lt;label&gt;Scope of Service &lt;label style='color:red'&gt;&lt;strong&gt;*&lt;/strong&gt;&lt;/label&gt;    &lt;br/&gt;&lt;/label&gt; &lt;input type='text' name='scope' length='50' id='ScopeofService' onblur='checkScopeofService()'/&gt;&lt;label id='labelScopeofService'&gt;&lt;/label&gt;&lt;/p&gt;"; 
</code></pre>

<p>This is followed by more labels and text fields. </p>

<p>And then the form tag is closed!</p>

<pre><code>echo "&lt;input type='hidden' name='dex' value={$dex}&gt;"; 
            echo "&lt;input type='hidden' name='sub' value=1&gt;"; 
            echo "&lt;input type='SUBMIT' style='background-color:white' name='submit' value='SUBMIT'&gt;"; 
            echo "&lt;/form&gt;"; 
</code></pre>

<p>Here's the function in validation.js</p>

<pre><code>function AdminDataCheck()
{
var SoS = document.getElementById('ScopeofService').value;
var PNumber = document.getElementById('ProjectNumber').value;
var numericExp = /^[0-9]+$/;
var alphaExp = /^[A-Za-z ]+$/; 
var Email = document.getElementById('Email').value;
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\-]+\.[a-zA-z0-9]{2,4}$/;

if (!(SoS.match(alphaExp)))
{   
alert("Invalid Scope");
return false;
}
else if(!(PNumber.match(numericExp)))
{
alert("Invalid Project Number.");
return false;
}
else if(!(Email.match(emailExp)))
{
alert("Invalid Email.");
return false;
}
else
{
return true;
}
}
</code></pre>

<p>Let me EMPHASIZE that this was working a few minutes ago and I made no changes, just restarted the browser and the server! And it stopped working. This is really frustrating!</p>
