Basically I want to perform this check:
var done = "<?= $test_details['done_test'] ?>";
if(typeof done == 'undefined'){
$('WORKING').appendTo('#bodyArea'); // just for testing (code here)
}
Obviously the check is using a value from an SQL query. So, what I want to do and cant seem to get working is:
on loading page: run query with PHP then run the JQuery which checks result value from query is not NULL.
this is what I have tried:
$(window).load(function () {
// code here
});
and:
$(document).ready(function () {
// code here
});
no luck with both.
Many thanks for help.
typeof donewould never be undefined since you’d always be defining it.If you want to run some jquery based on your PHP, you can try this
This way, the check is done on a PHP variable with PHP. When the page is processed, if the variable is empty PHP will output the JS making it run.
DEBUGGING
If you’re still having problems, put the code below and see what happens
If you’re not getting any output, then you’re doing something wrong. We’ll have to see your HTML.
If your getting that
$test_details['done_test'] is not emptymessage, then that means your earlier code was working properly because it was not executing if the variable was not empty