Im trying to get an js array filled out by the PHP (which will comde from a DB query). When I do the bolded PHP-in-JS it fails with a js error. (obejct expected, line 61)
Actually I would like to generate the Pic[] in js with the help of PHP. Any suggestions or ideas to get it work??
Thanks a lot,
/Serap
Code: Select all
<html>
<head>
<title>Photo Gallery - The Hour</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
$img_source[0] = '/main/images/hour_pg/1.jpg';
$img_source[1] = '/main/images/hour_pg/2.jpg';
$img_source[2] = '/main/images/hour_pg/3.jpg';
$img_source[3] = '/main/images/hour_pg/4.jpg';
$img_source[4] = '/main/images/hour_pg/5.jpg';
echo $img_source[1];
?>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
alert ("Alert 3");
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000;
// Duration of crossfade (seconds)
var crossFadeDuration = 100;
// Specify the image files
var Pic = new Array();
// to add more images, just continue
// the pattern, adding to the array below
<?php foreach ($img_source as $img) {
print "Pic[] = \'$img\' ;";
} ?>
//Pic[0] = '/main/images/hour_pg/1.jpg'
//Pic[1] = '/main/images/hour_pg/2.jpg'
//Pic[2] = '/main/images/hour_pg/3.jpg'
//Pic[3] = '/main/images/hour_pg/4.jpg'
//Pic[4] = '/main/images/hour_pg/5.jpg'
// do not edit anything below this line
var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
function runSlideShow() {
if (document.all) {
document.images.SlideShow.style.filter="blendTrans(duration=2)";
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply();
}
//line 61 is here
document.images.SlideShow.src = preLoad[j].src;
//document.images.SlideShow.src = a;
if (document.all) {
document.images.SlideShow.filters.blendTrans.Play();
}
j = j + 1;
if (j > (p - 1)) j = 0;
t = setTimeout('runSlideShow()', slideShowSpeed);
}
// End -->
</script>
</head>
<body onLoad="runSlideShow()" leftmargin="0" topmargin="0" >
<table width="500" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="500" height="335" valign="top" id="VU"><img src="/main/images/hour_pg/1.jpg" name='SlideShow' width="500" height="335"></td>
</tr>
</table>
</body>
</html>feyd | Please use [php] and
Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]