justAnoob Posted November 12, 2010 Share Posted November 12, 2010 I found a little javascipt online, and I wanted to play around with it. I'm trying to add a little php to it, I think I'm close to getting it, but when I click on the properties of the pictures that I want displayed, it has a bunch of extra garbage in it. So is the javascript reading something extra in the php script ? Here is the code. <script language="JavaScript"> var j,d="",l="",m="",p="",q="",z="",KW_ARI= new Array() KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; j=parseInt(Math.random()*KW_ARI.length); j=(isNaN(j))?0:j; document.write("<img name='seqSlideShow' src='"+KW_ARI[j]+"'>"); function seqSlideShow(t,l) { x=document.seqSlideShow; j=l; j++; if (j==KW_ARI.length) j=0; x.src=KW_ARI[j]; setTimeout("seqSlideShow("+t+","+j+")",t); } seqSlideShow(10000,0) </script> Link to comment https://forums.phpfreaks.com/topic/218490-php-in-javascript/ Share on other sites More sharing options...
Adam Posted November 12, 2010 Share Posted November 12, 2010 First off, it's much easier to define an array in JS like: var KW_ARI = [ '<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>', '<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>', '<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>', '<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>', '<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>' ]; (Remove "KW_ARI= new Array()" too) Secondly, what extra garbage? Link to comment https://forums.phpfreaks.com/topic/218490-php-in-javascript/#findComment-1133440 Share on other sites More sharing options...
justAnoob Posted November 12, 2010 Author Share Posted November 12, 2010 This is the extra garbage i was talking about when I checked the picture properties. The picture was not displaying cause of this. http://www.mysitecom/%3Cimg%20src=%22trackimages/daytonatrackpic.jpg%22%20/%3E I'll try what you said though. Thanks. Link to comment https://forums.phpfreaks.com/topic/218490-php-in-javascript/#findComment-1133452 Share on other sites More sharing options...
justAnoob Posted November 12, 2010 Author Share Posted November 12, 2010 Wow,, now I'm really confused. Basically I'm all I'm looking for is to have the pictures displayed for 10 seconds,, then move to the next one. Link to comment https://forums.phpfreaks.com/topic/218490-php-in-javascript/#findComment-1133455 Share on other sites More sharing options...
Adam Posted November 12, 2010 Share Posted November 12, 2010 You're defining part of the image tag within the array, and then again within the document.write calls: KW_ARI[KW_ARI.length]='<?php echo '<img src="trackimages/' . $row['new_pic'] . '" />'; ?>'; document.write("<img name='seqSlideShow' src='"+KW_ARI[j]+"'>"); Link to comment https://forums.phpfreaks.com/topic/218490-php-in-javascript/#findComment-1133465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.