Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

JAVA script (cycling) problem


  • Please log in to reply

#1
boob

boob

    Member

  • Member
  • PipPip
  • 74 posts
I'm having trouble setting up the JAVA scripting for the cycling banners. I'm trying to create 2 different banners on the same page that cycle through photos of houses. I can get one to work fine but when I add the scripting for the 2nd it causes neither to work. Here is the scripting:

<HTML>
<HEAD>
<TITLE> Cycling Banner Practice</TITLE>
<BODY>
<script>
imgArray = new Array(7);
imgArray[0] = new Image;
imgArray[0].src = "house1.jpg";
imgArray[1] = new Image;
imgArray[1].src = "house2.jpg";
imgArray[2] = new Image
imgArray[2].src = "house3.jpg";
imgArray[3] = new Image
imgArray[3].src = "house4.jpg";
imgArray[4] = new Image
imgArray[4].src = "house5.jpg";
imgArray[5] = new Image
imgArray[5].src = "house6.jpg";
imgArray[6] = new Image
imgArray[6].src = "house7.jpg";
index = 0;

function cycle ()
{
document.banner.src = imgArray[index].src;
index++;
if (index == 7)
{
index = 0;
}
setTimeout("cycle()",1000);
return;
}
</script>
<HEAD>
<BODY onLoad = "cycle();">
<CENTER>
<IMG SRC = "house1.jpg"
NAME = "banner"
WIDTH = 250

HEIGHT = 250>
</CENTER>
</BODY>
</HTML>

<HTML>
<HEAD>
<TITLE> Cycling Banner Practice</TITLE>
<BODY>
<script>
imgArray = new Array(7);
imgArray[0] = new Image;
imgArray[0].src = "house8.jpg";
imgArray[1] = new Image;
imgArray[1].src = "house9.jpg";
imgArray[2] = new Image
imgArray[2].src = "house10.jpg";
imgArray[3] = new Image
imgArray[3].src = "house11.jpg";
imgArray[4] = new Image
imgArray[4].src = "house12.jpg";
imgArray[5] = new Image
imgArray[5].src = "house13.jpg";
imgArray[6] = new Image
imgArray[6].src = "house14.jpg";
index = 0;

function cycle ()
{
document.banner.src = imgArray[index].src;
index++;
if (index == 7)
{
index = 0;
}
setTimeout("cycle()",1000);
return;
}
</script>
<HEAD>
<BODY onLoad = "cycle();">
<CENTER>
<IMG SRC = "house8.jpg"
NAME = "banner"
WIDTH = 250

HEIGHT = 250>
</CENTER>
</BODY>
</HTML>

Thanks for any help.
  • 0

Advertisements


#2
ditto

ditto

    - i pwn n00bs -

  • Member
  • PipPipPipPip
  • 1,260 posts
It looks like you are trying to have two different html pages in one. Why not making the two scripts into one?

<HTML>
<HEAD>
<TITLE> Cycling Banner Practice</TITLE>
<BODY>
<script>
imgArray = new Array(14);
imgArray[0] = new Image;
imgArray[0].src = "house1.jpg";
imgArray[1] = new Image;
imgArray[1].src = "house2.jpg";
imgArray[2] = new Image
imgArray[2].src = "house3.jpg";
imgArray[3] = new Image
imgArray[3].src = "house4.jpg";
imgArray[4] = new Image
imgArray[4].src = "house5.jpg";
imgArray[5] = new Image
imgArray[5].src = "house6.jpg";
imgArray[6] = new Image
imgArray[6].src = "house7.jpg";
imgArray[7] = new Image;
imgArray[7].src = "house8.jpg";
imgArray[8] = new Image;
imgArray[8].src = "house9.jpg";
imgArray[9] = new Image
imgArray[9].src = "house10.jpg";
imgArray[10] = new Image
imgArray[10].src = "house11.jpg";
imgArray[11] = new Image
imgArray[11].src = "house12.jpg";
imgArray[12] = new Image
imgArray[12].src = "house13.jpg";
imgArray[13] = new Image
imgArray[13].src = "house14.jpg";
index = 0;

function cycle ()
{
document.banner.src = imgArray[index].src;
index++;
if (index == 14)
{
index = 0;
}
setTimeout("cycle()",1000);
return;
}
</script>
<HEAD>
<BODY onLoad = "cycle();">
<CENTER>
<IMG SRC = "house1.jpg"
NAME = "banner"
WIDTH = 250

HEIGHT = 250>
</CENTER>
</BODY>
</HTML>

  • 0

#3
boob

boob

    Member

  • Topic Starter
  • Member
  • PipPip
  • 74 posts
That would work, but it only will give me 1 banner that cycles through 14 different houses. I need 2 different banners (the first banner cycles through houses 1-7 and the second banner cycles through houses 8-14).

Thanks for your help and any further help that you may have to offer. I appreciate it.
  • 0

#4
ditto

ditto

    - i pwn n00bs -

  • Member
  • PipPipPipPip
  • 1,260 posts
Would two banners be displayed at the same time?
  • 0

#5
ghostsofthestreets

ghostsofthestreets

    New Member

  • Member
  • Pip
  • 2 posts
i have a php code i use for that....i don't remeber where i got it

$extList['png'] = 'image/png';

$img = null;

if (substr($folder,-1) != '/') {
$folder = $folder.'/';
}

if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
file_exists( $folder.$imageInfo['basename'] )
) {
$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);

if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
}
}
if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
}
}
?>

make a folder called "random" and place all the images you want to cycle into it along with the above code saved as random.php,use <img src=/random.php> to place it. you could do more than one cycling image by making two folders (i.e:random1,random2) with two php documents (random1,random2)

that code will only work if you want it to change on refresh though,maybe if you made the image refresh every second somehow

Edited by ghostsofthestreets, 30 May 2005 - 09:54 AM.

  • 0

#6
boob

boob

    Member

  • Topic Starter
  • Member
  • PipPip
  • 74 posts
Yeah, 2 different ones would be displayed at the same time. I'm trying that other code out now. Thanks guys. :tazz:
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP