I have two javascript functions that should be executed when loading the page in PHP. Both are similar. Here is one of them:
<?php
if ($idAluno == $idRespA) {
echo '<script> window.onload = function(){ funcaoA() }; </script>';
} else {
$respA = $db->select('tbl_pessoas',['*'],['id'=>$idRespA]);
}
?>
The second part is the same. It only changes the IF, which compares with another variable and if it runs the B () function. But it's pretty much the same thing. Both are executed at the start of the page, one after the other.
The problem is that running it only works the 'window.onload' of one of them. So I guess this should not be the best way to run a JS at startup.
How would a JS run within PHP's IFs at page startup?
They also told me that it is not good to execute JS functions directly in PHP. Why?