ceruleansin Posted April 22, 2010 Share Posted April 22, 2010 I've been working on modifying a PHP gallery kit that can be found here. http://minishowcase.net/ Here is my implementation of it so far. http://ceruleansin.byethost3.com/gallery/ The file primarily responsible for displaying the enlarged image on the screen once you've clicked the thumbnail is /libraries/ajax.functions.js In this file I've added a few lines of script. This was so that I could get a nice mouse-over effect displaying some data when I mouse over the image. The purpose was to include basic info for each image like Title, Description, Dimensions, Price and Availability. Here is the code that I've added in HTML / Javascript, and yes I know this is a PHP forum, I'm getting there lol. imgout += '<a href="#" class="rollover_pointer" onmouseover="document.getElementById(\'overlay\').style.visibility = \'visible\';" onmouseout="document.getElementById(\'overlay\').style.visibility = \'hidden\';"><div id="overlay" style="position: relative; top:'+(fh-64)+'px; height: 100px;" class="overlay_info"><div class="overlay_info_contents">Title:<br>Size:<br>Medium:<br>Price:</div></div></a>'; The "imgout" variable is added to the source contents of a <div> when the image is called from the gallery. HERE IS MY PROBLEM. (About time, I know!) I need to dynamically add the contents (ie. Title, Description, Dimensions, Price and Availability). There are several ways of getting the data I know of, including reading it from a text file or populating an array from a static PHP page that contains the list. Either way, I need my script to function like the following. imgout += '<a href="#" class="rollover_pointer" onmouseover="document.getElementById(\'overlay\').style.visibility = \'visible\';" onmouseout="document.getElementById(\'overlay\').style.visibility = \'hidden\';"><div id="overlay" style="position: relative; top:'+(fh-64)+'px; height: 100px;" class="overlay_info"><div class="overlay_info_contents"><?php echo $image_array[0] ?></div></div></a>'; To summarize, is there a way to dynamically add info from a PHP array to a *.js file BEFORE its sent to the user? Thanks for all you help!! Yay PHPFreaks! PS. I've included a stripped version of my gallery in RAR. Just code, no images. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/199387-including-php-script-calls-in-a-js-file/ Share on other sites More sharing options...
andrewgauger Posted April 22, 2010 Share Posted April 22, 2010 Yes, the easiest being: <script language="javascript" src="file.php"></script> The php will be executed, the javascript returned. Quote Link to comment https://forums.phpfreaks.com/topic/199387-including-php-script-calls-in-a-js-file/#findComment-1046581 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.