I'm trying to validate a form with jQuery without using any plugin and my first problem is that the function validateLogin()
is not called after hitting submit . In the below snippet everything is working just fine ,but on my pc is not .
function validateLogin() {
$('#login-form').find('input').each(function() {
var $this = $(this);
var inputName = $this.attr('name');
var value = $this.val();
alert(" value of "+ inputName + " = " + value );
})
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<form class="login-form" id="login-form" name="login" method="get" onsubmit="return validateLogin();" >
<div class="form-group">
<label class="login-label" for="usermail">Already a member?</label>
<input class="form-control" type="text" name="usermail" id="usermail" placeholder="Username or Email" value="">
<input class="form-control" type="password" name="password" id="password" placeholder="Password">
<button class="form-control btn btn-danger" type="submit" id="login-button" >Login</button>
</div> <!-- end form-group -->
</form> <!-- end login-form -->
edit: so I was getting "Uncaught ReferenceError: validateLogin is not defined " in the console .After a quick research I found out that validateLogin shouldn't be inside $(document).ready
. Can someone explain why ?