How could I use jquery to check if text-fields are empty when submit without loading login.php
?
<form action="login.php" method="post">
<label>Login Name:</label>
<input type="text" name="email" id="log" />
<label>Password:</label>
<input type="password" name="password" id="pwd" />
<input type="submit" name="submit" value="Login" />
</form>
Thanks.
You can use 'required' http://jsbin.com/atefuq/1/edit
}
I really hate forms which don't tell me what input(s) is/are missing. So I improve the Dominic's answer - thanks for this.
In the css file set the "borderR" class to border has red color.
A simple solution would be something like this
Note: The
jQuery.on()
method is only available in jQuery version 1.7+, but it is now the preferred method of attaching event handlers.This code loops through all of the inputs in the form and prevents form submission by returning false if any of them have no value. Note that it doesn't display any kind of message to the user about why the form failed to submit (I would strongly recommend adding one).
Or, you could look at the jQuery validate plugin. It does this and a lot more.
NB: This type of technique should always be used in conjunction with server side validation.
you should try with jquery validate plugin :