Basic php question. add javascript to .php page

Hi, I am not a php developer, I have never touched it. but I was asked to add the Google Cart Tracking Code to the site. when someone completes the order, and then sent to the finishorder.php file. when i go to finishorder.php file it looks like this:

include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();

which looks like a script server for me (coming from the .net background), so I assume I can't add javascript here, how did php decide to get the layout for this page? how can i add javascript code to this page.

+3
source share
3 answers

You can do it:

include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();

echo '<script type="text/javascript">YOUR JS HERE</script>';

OR

<?php
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
?>
<script type="text/javascript">YOUR JS HERE</script>

Hm?

, HandlePage() - , Class ISC_ORDER- > handlePage(), ... ...

EDIT:

<?php
echo '<script type="text/javascript">//<!--
        alert("Hello to multiline JS script");
        alert("Do You get it?");
    //--></script>';
?>
+9

javascript php-

<?php echo "<script> alert('this is a javascript code')</script>"; ?>
+4

You can add a script on a PHP page in two ways

The first way is to add it to PHP tags

<?php 
//PHP CODE
if($_POST['submit']){
echo '<script>alert('Hello')</script>';
}
?>

The second way is to add it after the PHP code.

<?php 
//PHP CODE
?>
<script>
alert('Hello');
</script>
+1
source

All Articles