0

Hi all. I'm trying to implement a rotating image system written in Javascript into a PHP website. The PHP page and the Javascript both work fine independently, but integrating the JS is proving tough and giving me errors.

Here is the top part of the PHP page:

<?
include ("./application.php");
include ("./functions.php");
include ("./database.php");

After line 4 I would like to implement the following Javascript:

<!--webbot bot="HTMLMarkup" startspan --><script language="JavaScript"><!--

//store the quotations in arrays

images = new Array(2);

images[0] = "<a href = 'http://www.niburu.nl/index.php?articleID=22481'><img src='http://www.niburu.nl/img/blooms2.jpg' border=0></a>";

images[1] = "<a href = 'http://www.flexwebhosting.nl/'><img src='http://www.niburu.nl/img/flexweb2.jpg' border=0></a>";

index = Math.floor(Math.random() * images.length);

document.write(images[index]);

//done

// --></script><!--webbot bot="HTMLMarkup" endspan -->&nbsp;&nbsp;<!--webbot bot="HTMLMarkup" startspan --><script language="JavaScript"><!--

//store the quotations in arrays

images = new Array(1);

images[0] = "<a href = 'http://www.niburu.nl/index.php?articleID=22449'><img src='http://www.niburu.nl/img/spieghel2.jpg' border=0></a>";

index = Math.floor(Math.random() * images.length);

document.write(images[index]);

//done

// --></script><!--webbot bot="HTMLMarkup" endspan -->&nbsp;&nbsp;<!--webbot bot="HTMLMarkup" startspan --><script language="JavaScript"><!--

//store the quotations in arrays

images = new Array(1);

images[0] = "<a href = 'http://www.niburu.nl/index.php?articleID=22551'><img src='http://www.niburu.nl/img/letsclean.jpg' border=0></a>";

index = Math.floor(Math.random() * images.length);

document.write(images[index]);

//done

// --></script><!--webbot bot="HTMLMarkup" endspan -->

Any ideas how I can get this to display properly? Simply pasting the JS isn't working, and I'm not too good at the whole coding thing. Thanks for any help, I really appreciate it.

5
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Rec3000
0

dont use javascript,
try php to randomize the images as well, there is no user input, there need be nothing clientside

array() and rand() in php

has the bonus there is less to download, cant be blocked if javascript is disabled

0

almostbob's idea is probably better. But, if you have to use JavaScript, you will have to close the PHP block before you include it then re-open it after the JS. Otherwise, your JS will get eaten by the PHP parser and cause issues.

Edited by Fbody: n/a

0

Fbody is right,

after your include statements, close it off

?>
put JS here
<?

Edited by gteh: n/a

0

Thanks guys, I fiddled around with the suggestions and got it to display more or less correctly, it'll just take a little additional tweaking.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.