Where am I going wrong with my programming logic here?
I have 2 php files. File 1 includes File 2. File 1 calls a php function from File 2. Inside the php function there is a bunch of html. The html works perfectly. At the end of the function I have this javascript….
<script type="text/javascript">
alert('hello');
</script>
This javascript isn’t alerting “hello”.
What am I doing wrong?
Thank you in advance.
EDIT: New question because I skrewed the last one up.
In theory would the code below run properly? (yes/no)
<?php function AlertHelp(){
?><script>
alert('help');
</script><?
AlertHelp();
?>
Long shot on a wild guess here with the limited information you gave.
My assumption is that you are not “including” the file via PHP’s
include,require,include_onceorrequire_oncefunctions, but are in fact using AJAX to load in the page’s content.If this is the case, then I shall also assume you’re using
innerHTMLto put the content on the page.Suddenly the solution is obvious:
<script>tags added byinnerHTMLare not parsed and run. You could probably do something like this:Please note however that
evalshould be avoided if possible. Consider redesigning your layout to use callbacks instead.