web_master Posted December 3, 2013 Share Posted December 3, 2013 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.... Quote Link to comment https://forums.phpfreaks.com/topic/284484-confirm-password-without-submit-jquery/ Share on other sites More sharing options...
Irate Posted December 3, 2013 Share Posted December 3, 2013 $("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. Quote Link to comment https://forums.phpfreaks.com/topic/284484-confirm-password-without-submit-jquery/#findComment-1461113 Share on other sites More sharing options...
codefossa Posted December 3, 2013 Share Posted December 3, 2013 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"); } } Quote Link to comment https://forums.phpfreaks.com/topic/284484-confirm-password-without-submit-jquery/#findComment-1461132 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.