Jump to content

php in javascript


justAnoob

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.