Hello I\'m implementing a login page everything is working fine from the PHP side but now I would implement one more function using jQuery: I would like to check if the fiel
Bind an event to the submission of the form (Note: NOT the click of a submit button). That's where your code goes that checks the form, and if necessary, stops it from being posted.
$('#loginForm').on('submit', function(e){
if ($('#login').val()=='' || $('#password').val()==''){
e.preventDefault();
// alert('Fill in both fields');
// You can use an alert or a dialog, but I'd go for a message on the page
$('#errormsg').text('Fill in both fields').show();
}else{
// do nothing and let the form post
}
});
If you prefer to show a message than use a dialog, somewhere on the page, preferably near the Submit button add the errormsg div
<p id="errormsg" style="display:none;"></p>