the problem with integrating jquery into submit form
Hi!
I have a login form with set defaultValues. I want to mistakes jump out when the login and password are empty or when they are default. But that does not work. I tried this and that, but got troubled. The mistakes should jump out in ids "login_err" and "pass_err".
Please help.
My form:
- <div id="login">
- <form method="post" style="background:inherit">
- <table style="align:right;text-align:right;margin:0 auto;">
- <tr>
- <td id="login_err"></td>
- </tr>
- </table>
- <input id="login_name" name="login" type="text" value='Логин' onfocus= "if(this.value == 'Логин') { this.value = '' }" onblur = "if(this.value == '') { this.value = 'Логин'}" > </br>
- <table>
- <tr>
- <td id="pass_err"></td>
- </tr>
- </table>
- <input id="pass" type="password" name="password" value="Пароль" onfocus= "if(this.value == 'Пароль') { this.value = '' }" onblur = "if(this.value == '') { this.value = 'Пароль'}"></br>
- <input type="submit" id="log" value="войти">
- <a href="registration.html"> <input type="button" value="регистрация"></a>
- </form>
- </div>
Jquery code:
- $(function(){
-
- $("#log").submit(function(){
- var evt= e||window.event;
- evt.preventDefault();
- var hasError = false;
-
- var login=$("#login_name").val();
- if (login=="" || login=="defaultValue")
- {
- $("#login_err").html("You forgot to enter login");
- hasError=true;
- }
- var password=$("#pass").val();
- if (password=="" || password=="defaultValue")
- {
- $("#pass_err").html("You forgot to enter password");
- hasError=true;
- }
-
- if(hasError == false) {
- $(this).hide();
- $("#log").before('<img src="ajax-loader.gif" alt="Loading" id="loading" />');
- $.ajax ({
- type: "POST",
- url: "sendemail.php",
- data: $("form").serialize(),
- success: function(data) {
-
- document.location.href = "paymentfinal.html";
- }
- });
- }
- return false;
- });
-
- });