I've got a variable named allow
which I want to be global, so any other function will be able to use it. What happens is, when I call the variable from a certain function, it returns undefined
.
Here's my code:
var allow = null;
$('#form').submit(function(e) {
error_found = false;
$('#text').click();
console.log(window.allow);
if(window.allow == false) {
alert('מספר הסדר שהוזן הינו בשימוש, נא בחר מספר אחר, או סדר את רשימת הסדר מחדש.');
$("#order").focus();
e.preventDefault();
error_found = true;
}
if($("#fix_rel").val() == "" && !error_found){
alert('נא בחר זמן יחסי או קבוע.');
$("#fix_rel").focus();
e.preventDefault();
}
if($("#fix_rel option:selected").val()=="rel" && !error_found){
if(!$.isNumeric($("#order").val())){
alert('מספר הסדר חייב להיות מספר!');
$("#order").focus();
e.preventDefault();
}
}
});
$('#text').click(function() {
table = $("#table").val();
order = $("#order").val();
$.post('test.php',{table:table,order:order}).done(function(data) {
if(data == "true") {
window.allow = true;
}
if(data == "false") {
window.allow = false;
}
console.log(window.allow);
});
});
I've been trying to solve it for the past 2 hours, and so far, I have NO clue.
Thanks in advance!