Reputation: 12998
I am trying to check whether or not the password field on a form has been filled in on submission on a form but it always returns as "undefined" so the code I'm trying to run when the form is submitted never runs.
The username field seems to work fine though.
Here's my code...
$("#form1").find("input[type=submit]").click( function() {
if($(".username").val() != "" && $(".password").val() != "") {
console.log("Success")
} else {
console.log("fail");
}
});
Upvotes: 0
Views: 986
Reputation: 40717
Something must be wrong with your html since it seems to work:
<form id="form1" method="post">
<input type="text" class="username">
<input type="text" class="password">
<input type="submit" value="Submit">
</form>
I have a feeling that you might be confusing classes that are selected with a "." with id's that are selected with a "#", but if I don't see your html, I'm just guessing.
Upvotes: 1