I've declared a variable in the first .click function, but on my second .click I am trying to get the first variable value, but it's not been able to find it, due to it being in a different function.
How can I set a global variable or something where other functions can use the value too?
$('input[type="checkbox"]').click(function(){
var checked = 0;
if($(this).prop("checked") == true){
var checked = 1
console.log('checked');
console.log(checked);
}
else if($(this).prop("checked") == false){
var checked = 0
console.log('not checked');
console.log(checked);
}
});
$('#button-cart').click(function(){
if(checked == 1){
alert('can continue fine');
} else if(checked == 0){
alert('cannot continue');
}
})
Error: Uncaught ReferenceError: checked is not defined