Reputation: 2880
Here is my form,
<form action="" method="post" id="signupform">
<input class="email" id="email" type="email" placeholder="[email protected]" />
<input type="submit" value="submit"/>
</form>
Here's javascript,
$(document).ready(function(){
$('#signupform').submit(function(){
return valid_email();
});
});
function valid_email(){
var email = $('#signupform > #email ').val();
alert(email);
return false;
}
It, alerts "Undefined" but, if I use, only $('#email')
, I get correct value. Where I am making the mistake.
Upvotes: 1
Views: 58
Reputation: 148120
Assign initial value to the textbox then you will be able to get it the placeholder is not taken by val() and show empty.
$(document).ready(function() {
$('#signupform').submit(function() {
return valid_email();
});
});
function valid_email() {
var email = $('#signupform > #email ').val();
alert(email);
return false;
}
Upvotes: 1