简体   繁体   中英

Validation error besides textbox

I have validation error display besides text box. The value -1, shows error, while the value 0 show alert that the password is correct. The first time user input incorrect password, it display the validation error.

However, the second time it have wrong input, the validation error does not show. I console log the value, it still show the error value(-1) but the validation message doesn't show up. I couldn't see what's wrong with my code.

I'm using if else statement. Does anyone expert could pointed out what might be the cause of this?

  var clearFields = function() {
    $('#current_pwd').val('');
    $('#new_pwd').val('');
    $('#retype_pwd').val('');

    $('#current_label').html('');
    $('#new_label').html('');
    $('#retype_label').html('');

    $('#current_label').prop('hidden',true);
    $('#new_label').prop('hidden',true);
    $('#retype_label').prop('hidden',true);
  }
  var changePassword = function () {
    var $result = {};
        $.ajax({
            url: "users/resetpwd",
            type: "POST",
            async: false,
            data: $("#changePasswordID").serialize(),
            success: function(result) {
                $result = $.parseJSON(result);
            }
        });
    console.log($result["ret"]);


    if($result["ret"] == -1) {
        $result["ret"] == -1;
        $('#current_label').html($result["curr_msg"]);
        $('#new_label').html($result["new_msg"]);
        $('#retype_label').html($result["ret_msg"]);

        $('#current_label').prop('hidden',false);
        $('#new_label').prop('hidden',false);
        $('#retype_label').prop('hidden',false);
        alert('Password does not match.');          

    } else if($result["ret"] == 0) {

        $('#current_label').prop('hidden',true);
        $('#new_label').prop('hidden',true);
        $('#retype_label').prop('hidden',true);
        alert('Password Changed.');
        clearFields();
     };
  };

reset the counter to its default value at the start of your validation. Then as the validation runs, it will change the counter -1 or 0 depending on the user input. See if that works.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM