I have a button that when clicked should delete a cookie, call a function that collects a value from a textbox and save it as the new cookie value.
The problem I'm having is that after the button is clicked, the function is executing as if there was a value in the cookie.
I've logged the value of the cookie and it's showing null. Why isn't my function finding that the value is null?
//when new player is pressed
$('#BtnPlayAsNew').button().click(function () {
$.cookie('name', null); //delete cookie
$('#Result').hide();
getUsername(); //call function
});
function getUsername() {
//get cookie
var cookie = $.cookie('name');
//check value of cookie
if (cookie == null || cookie == "") {
$('#controls').hide();
$('#NewUser').show();
$('#BtnUser').click(function () {
name=$('#tbUser').val();
$.cookie('name', name,{path:'/' });
$('#NewUser').hide();
$('#controls').show();
});
}else{
$('#NewUser').hide();
$('#controls').show();
}
}