4

Hi i am not a php developer, ive never touched it before. but i have been asked to add a google shopping cart tracking code to a website. when someone completes an order then get sent to finishorder.php. when i go the 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 just looks like server script to me (coming from a .net background), so i presume i cannot add the javascript here, how does php decide get the layout for this page? how can i add the javascript code to this page.

1
  • You need to find out what the view for your final page is. There must be a template file somewhere Commented May 4, 2011 at 11:02

3 Answers 3

12

You can do this:

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>

But I think that HandlePage() method will do something with our page so I'd look inside this method: class ISC_ORDER->handlePage() what it does... You can then echo your <script> within this method at appropriate place...

EDIT:

<?php
echo '<script type="text/javascript">//<!--
        alert("Hello to multiline JS script");
        alert("Do You get it?");
    //--></script>';
?>
Sign up to request clarification or add additional context in comments.

2 Comments

ive found the handlepage method where i can add the echo, but my script runs over multiple lines: do i need to do anything special in this case??
if it is inside apostrophes or double quotes and extends over more lines, You do not need to do anything... In PHP the strings can be over more lines without any need of concatenation... I'll edit my post to show you an example...
5

You can add javascript inside a php code as

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

Comments

1

You can add script in PHP page by 2 ways

The first way is to add it in PHP tags

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

The second way is to add it after PHP code

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.