I've got a little problem with JQuery .val() used on an id of an input. I've tried many fruitless things so here I am.
I just try to get the value of the email input (what the user typed in before submition) when the user submits the form, but all I have is an empty line in the console (not even undefined value ?)
EDIT : It appears to work here, so my question is now why does this code not work ? Maybe my JQuery version is to old ?
Here is a simple version of my code, the script is at the end of the page (page system of JQuery mobile) so after the html of the concerned page.
$('#loginForm').submit(function() {
var email = $("#email").val();
console.log(email);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<form action="#test" id="loginForm">
<div data-role="fieldcontain">
<input type="email" name="email" id="email" placeholder="Email" />
</div>
<div data-role="fieldcontain">
<input type="password" name="password" id="password" placeholder="Pwd" />
</div>
<input type="submit" id="submit" value="Login" />
</form>
Thanks a lot for your time.
.val()has been included in jQuery since version 1.0. Maybe you have another#emailelement on the page that is higher up in the DOM that is being selected? This can happen somewhat easily with jQuery Mobile sites.$(document).ready?