Jump to content

Confirm password without submit jquery


web_master

Recommended Posts

I can't find how can I validate (confirm) password width jQuery without submit. Mean, when I type the password confirmation to see immediatly is correct or not.

 

 

<input type="password" name="password" autocomplete="off" value="password" maxlength="12" />
<input type="password" name="password" autocomplete="off" value="passwordconfirm" maxlength="12" />

 

 

I can't find script without submit form....

Link to comment
https://forums.phpfreaks.com/topic/284484-confirm-password-without-submit-jquery/
Share on other sites

$("input[type='password']:eq(0)").on("change",function(){
var next = $("input[type='password']:eq(1)");
if(!next.val().trim()) return;
if(next.val()==$(this).val()) // passwords match, do something
$(next).addClass("correct-pass");
else
$(next).addClass("wrong-pass");
});
$("input[type='password']:eq(1)").on("change",function(){
var prev = $("input[type='password']:eq(0)");
if(!prev.val().trim()) return;
if(prev.val()==$(this).val())
$(this).addClass("correct-pass");
else
$(this).addClass("wrong-class");
});

It's just an example of how to implement that. There's some other ways, too.

Maybe just use a function that checks both rather than two functions to check the same thing.

 

JSFiddle: http://jsfiddle.net/LKr8G/

 

// The input fields.
var inputs = $("input[type='password']");

// The output message element.
var output = $("span");

// Run the check as the password is typed.
inputs.keyup(check);

// On change, run the check.
inputs.change(check);

// Function to compare passwords.
function check()
{
	// Check if the fields' values are the same.
	if (inputs[0].value == inputs[1].value)
	{
		// Yay!  They match.
		output.html("Passwords match!").css("color", "#090");
	}
	else
	{
		// Let's tell them the bad news.
		output.html("Passwords do not match.").css("color", "#900");
	}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.