Anik
Anik

Reputation: 2880

jQuery child of a parent selection with id

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

Answers (1)

Adil
Adil

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.

Live Demo

$(document).ready(function() {
    $('#signupform').submit(function() {
        return valid_email();
    });
});

function valid_email() {
    var email = $('#signupform > #email ').val();
    alert(email);
    return false;
}​

Upvotes: 1

Related Questions