SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: PHP data to JS

  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP data to JS

    Hi All,

    I read the Sitepoint Books about PHP and the JS anthology, but cannot integrate the two.
    Here's my problem:

    For the " IDEAL payment engine" for my site I received a Script which needs the order total.

    Snippet:


    <!-- CODE_START -->
    <script type="text/javascript">
    <!-- Begin
    var Amount = 123;
    var PSPID = "TESTiDEALEASY";


    The manual states that I should replace the 123 (red) with the order total (dynamicaly)

    My shoppingcart is coded in PHP and the total is therefore known as $total But if I just paste this into the JS code, I receive an error NaN (not a number)

    So var Amount = $total;

    Does not work.

    What am I doing wrong ?
    Please help

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    var Amount = <?php echo $total; ?>

    Echoing javascript is no different then echoing HTML.

  3. #3
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by stymiee View Post
    var Amount = <?php echo $total; ?>

    Echoing javascript is no different then echoing HTML.
    Excellent!
    All functional, tested and ready to go.

    Thanks a lot.


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
  •