Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help needed adding PHP variable into javascript

    Hello, I am trying to call an image filename and the page title into a section of javascript located within a php file in the "head" section. The js is part of a shopping cart. My problem is with inserting the PHP variables between the " ". When viewing the source code of the generated page, the PHP has been ignored and it is blank between the " ".

    I've been working on this for most of the day and nothing seems to work. I dont' know what to try next. I know it has something to do with php being ignored in the script type= text/javascript, but what I've found through google searches has not solved the problem. I don't understand javascript very well, but could that be a solution for calling the gallery name and filename?

    Does anyone have any idea on how I can get this to work??? I appreciate any help or direction offered.

    <script type="text/javascript">

    <!--
    function CalculateOrder(form)
    {

    if (document.myform.os0.value == "5x7")
    {
    document.myform.amount.value = 10.00;
    document.myform.item_name.value = "<?= $page_title ?>";
    document.myform.item_number.value = "<?= $item->title) ?>";
    }

    }
    -->
    </script>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    What does the PHP source look like? The PHP runs before the JavaScript so the way they are combined together has to take that into account.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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