Darko Petkovski
Darko Petkovski

Reputation: 3912

Form validation - Unexpected end of input

I have a form that i check if passwords are same, but i get Unexpected end of input error. Can anybody tell me where is my mistake?

JS Code:

<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> 

and form html code:

<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>

Upvotes: 0

Views: 322

Answers (2)

Bjarke
Bjarke

Reputation: 91

Yup missing }); Also you should consider using type="password" for your input fields. Like this:

<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>

Upvotes: 3

MrCode
MrCode

Reputation: 64536

You haven't closed your $( document ).ready( call. The closing }); is missing.

$( 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

Upvotes: 2

Related Questions