SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to give javascript my phpvars

    I have slideshow for images built with javascript.
    The images are in a db and being stored as a blob type. I have the right scripts to display the images. Now i would like to use this javascript to make a slideshow out of the images. The problem is that I would like to change the id of image but I guess itīs not possible to just code the php within the javascript. Can anyone help please?

    This what i have right now:
    Code JavaScript:
    var mySlideList1 = 
    ['/php/img.php?id=1&ref=1', '/php/img.php?id=2&ref=1', '/php/img.php?id=3&ref=1', '/php/img.php?id=4&ref=1', '/php/img.php?id=5&ref=1'];

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,478
    Mentioned
    162 Post(s)
    Tagged
    1 Thread(s)

    php vars in javascript

    If the javascript code is in a PHP file you can use the PHP variables in it. eg.
    PHP Code:
    var jsvar = <?php echo $phpvar?>;
    or
    PHP Code:
    $jscode = <<< JSC
    <script type="text/javascript">
    var jsvar = 
    $phpvar;
    </script>
    JSC; 
    or
    PHP Code:
    echo '<script type="text/javascript">var jsvar = ' $phpvar '</script>'


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
  •