SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Nov 2000
    Posts
    740
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding a variable

    I want to use a variable to set a value. The code is below is on mysite.com/tracked.php:

    Code:
    <!-- Google Code for purchase Conversion Page -->
    <script language="JavaScript" type="text/javascript">
    <!--
    var google_conversion_id = 3454565;
    var google_conversion_language = "en_GB";
    var google_conversion_format = "1";
    var google_conversion_color = "454545";
    if (theAmount) {
      var google_conversion_value = theAmount;
    }
    var google_conversion_label = "purchase";
    //-->
    </script>
    <script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
    </script>
    <noscript>
    <img height=1 width=1 border=0 src="http://www.googleadservices.com/pagead/conversion/56756756/imp.gif?value=theAmount&label=purchase&script=0">
    </noscript>
    mysite.com/nearlyfinished.php has the following code on it (amongst other things!):

    Code:
    <meta http-equiv="refresh" content="4;URL=http://www.mysite.com/tracked.php?amount=$theAmount">
    The idea is that I want to have the "amount" variable passed from one page to the other and then that variable put into the javascript so that I can have dynamic amounts, depending on how much the customer spent. But I don't know javascript so was hoping someone here might advise me.

    Do I need anything at the top of mysite.com/tracked.php such as:

    PHP Code:
    <?php 
    $theAmount 
    $_REQUEST['amount']; 
    ?>
    Does javascript automatically pick this up or do I need something in the javascript code to declare a variable or something??? :S

    Thanks,

    Jon

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give this a go:

    nearlyfinished:
    Code:
    <meta http-equiv="refresh" content="4;URL=http://www.mysite.com/tracked.php?amount=<?php echo $theAmount ?>">
    tracked:
    Code:
    <!-- Google Code for purchase Conversion Page -->
    <script language="JavaScript" type="text/javascript">
    <!--
    var theAmount = <?php echo $_REQUEST['amount'];?>;
    var google_conversion_id = 3454565;
    ...

  3. #3
    SitePoint Guru
    Join Date
    Nov 2000
    Posts
    740
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How stupid of me to miss the echo on the refresh. Doh!

    I presume I can still use $theAmount = $_REQUEST['amount']; in the header and use <?php echo $theAmount ?> in the javascript?




  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, you can use $theAmount instead.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •