2013-10-11 11 views
0

我有一個表格,我檢查密碼是否相同,但我得到Unexpected end of input錯誤。有誰可以告訴我我的錯誤在哪裏?表單驗證 - 意外的輸入結束

JS代碼:

<script> 
$(document).ready(function() { 
    $("form").submit(function(event) { 
    var $form = $(this); 
      if($form.find('#password').val() !== $form.find('#password2').val()) { 
       event.preventDefault(); 
       alert('Passwords do not match.'); 
     } 

    }); 

</script> 

和形式的html代碼:

<form name="form1" method="post" action="process_reset.php"> 
<img src="../images/login_icon.png" class="form-icon"/><div id="clr"></div><span style="float: left;padding-left: 10px;"> 
<b>Welcome admin.</b> <i>Reset your password</i></span><br/> 
<input name="password" type="text" class="login-text-lbl" placeholder="password" id="password"><div id="clr"></div> 
<input name="password2" type="password2" class="login-text-lbl" placeholder="repeat password" id="password2"><div id="clr"></div> 

<input name="admin_id" type="text" value="<? echo $client_id; ?>" style="display: none;" id="admin_id"/> 

<input type="submit" id="resetBtn" name="Submit" value="Reset password" class="login-button"> 
</form> 

回答

2

您還沒有關閉您的通話$(document).ready(。關閉});缺失。

$(document).ready(function() { 
    $("form").submit(function(event) { 
    var $form = $(this); 
      if($form.find('#password').val() !== $form.find('#password2').val()) { 
       event.preventDefault(); 
       alert('Passwords do not match.'); 
     } 

    }); 
}); // <-- this was missing 
3

Yup missing}); 另外,您應該考慮在輸入字段中使用type =「password」。像這樣:

<input name="password" type="password" class="login-text-lbl" placeholder="password" id="password"> 

<div id="clr"></div> 
<input name="password2" type="password" class="login-text-lbl" placeholder="repeat password" id="password2"><div id="clr"></div>