jquery .val() returns undefined
<p>The relevant part of the code is shown below. When I click the Submit button, on the alert box, I get undefined, rather than the typed email. What mistake am I doing here?</p>

<pre><code>&lt;form action="page2.php" method="post" onsubmit="myFunction()" id="form1"&gt; 
        ......
        &lt;input type="text" name="YourEMail" style="width: 250px;"&gt; 
        &lt;input type="submit" name="submit" value="Submit"&gt; &lt;br&gt;
        ......
&lt;/form&gt; 

&lt;script&gt;
$('#form1').submit(function() {
    //your validation rules here
    var email = $('#YourEMail').val()
    alert(email)
    //if(email.length == 0)
        return false;
    //else 
    //  return true;
});
&lt;/script&gt;
</code></pre>