In the following code every time button is clicked the alter shows the value of the variable counter=20 which is the value of null text box.
Kindly guide regarding this.
var username = $("#<%= uname.ClientID %>").val();
var pwd = $("#<%= pwd.ClientID %>").val();
var counter = (function () {
var counter1 = 0;
return function () {
if (username == "DEF" && pwd == "5678") {
counter1 = 6;
}
else if (username == "" && pwd == "") {
counter1 = 20;
}
else {
counter1 = -1;
}
return counter1;
};
return false;
})();
$("#<%= Login.ClientID %>").click(function makecounter1() {
counter();
if (counter() != -1) {
alert(counter());
}
else {
alert("Wrong Credentials");
}
return false;
});
Why counter doesn’t show other value.
The values are set when the page is loaded and is not getting refreshed.
move the code
into the function
counterand it should work.