SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,618
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    use php variables in javascript

    Is it possible to use php variables in my javasript?
    HTML Code:
    <script type="text/javascript">
    function loadImg(img){
    var imgName = "$image1"; // name of the big image
    var srcs = ["$image1","$image2","$image3","$image4","$image5","$image6"]; // array of SRC's for the big images
    
    document.images[imgName].src=srcs[img];
    }
    </script>
    How?
    Thanks.
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if this is the case

    PHP Code:
    <?
    $image1 
    '234.gif';
    $image2 '234.gif';
    $image3 '234.gif';
    $image4 '234.gif';
    $image5 '234.gif';
    $image6 '234.gif';
    echo 
    "
    <script type="
    text/javascript"> 
    function loadImg(img){ 
    var imgName = '
    $image1'; // name of the big image 
    var srcs = ['
    $image1','$image2','$image3','$image4','$image5','$image6']; 
    // array of SRC's for the big images document.images[imgName].src=srcs[img]; } 
    </script>"
    ;
    ?>

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,618
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    thanks
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If you want to put it in an external file simply link it using:

    <script type="text/javascript" src="externaljs.php"></script>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •