I am having a problem setting a value to a variable. My code is as below.
function fpform(){
var response_new = '';
var password_reset = "";
var fpemail = $('#frgtpwd').val();
//var fpemail = document.getElementById('frgtpwd').value;
if (fpemail == ""){
$('span#fperror').text("insert your emal address");
//document.getElementById('fperror').innerHTML = "Insert your email address";
password_reset = 'no';
} else {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(fpemail)==false) {
$('span#fperror').text("Email address is not in valid format");
//document.getElementById('fperror').innerHTML = "Email address is not in valid format";
password_reset = 'no';
} else {
$("#loader").html('<img src="images/ajax-loader.gif" />');
$.post("forgot_password_process.php", {
email:fpemail
}, function(response){
response_new = response.trim();
}).success(function () {
if (response_new == 'yes'){
$("#fperror").html('<font color="green"><b>Your password has been reset now and emailed to you </b></font>');
$("#loader").empty();
password_reset = 'yes';
} else {
$("#loader").empty();
$("#fperror").html('<font color="black"><b> Email address was not found in database!</b></font>');
password_reset = 'no';
}
});
}
}
if (password_reset == "yes"){
alert(password_reset);
return true;
} else {
alert(password_reset);
return true;
}
}
The last if condition is checking if the password_reset variable is set to yes or not and returns true or false depending on that. But the alert displays blank value of the password_reset variable. I can't seem to find a problem behind this as the password_reset variable should get assigned before reaching the last if. can anyone please suggest a solution.
Kind Regards