I have a simple register form and i decide to add the feature of confirmation my password and it doesn't seem to check even if i type a different password!
Is there an error in my code?
$(document).ready(function(){
$('input[name=c_password]').keyup(password_check);
});
function password_check(){
var password = $('input[name=password]').val();
var c_password = $('input[name=c_password]').val();
if(c_password != password || c_password.length < 6){
//alert("test");
$('input[name=c_password]').parent().addClass( "has-error has-feedback" );
}else{
$('input[name=c_password]').parent().removeClass( "has-success has-feedback" );
}
}
Thanks!
You code is almost right, except that you forget to remove the class has-error in case of correct the c_password.
$('input[name=c_password]').parent().removeClass("has-error")
if(c_password != password || c_password.length < 6){
//alert("test");
$('input[name$=password]').parent().addClass( "has-error has-feedback" );
}else{
...
(you need put a 'url' on ajax)
It looks like you've just ommited some code. From what you've provided I'm guessing you want something like this:
if(c_password != password || c_password.length < 6){
// This is the additional code
$('input[name=c_password]').parent().addClass( "has-error has-feedback" );
}else{
jQuery.ajax({
success: function(response){
...
}
}
Something along those lines should highlight an error to the user. Don't forgot to validate server-side too, client-side is just for user convenience.
EDIT: actually, let's ignore that last edit :/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.