WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : JavaScript Image Rotator - cycle images or ads randomly or sequentially even of different sizes.
Categories : Java Script, Graphics Click here to Update Your Picture
Bobin R
Date : Mar 09th 2007
Grade : 3 of 5 (graded 1 times)
Viewed : 5300
File : 4598.zip
Images : No Images for this code example.
Search : More code by Bobin R
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Sometimes you may want to cycle affiliate ads on your site from an array of ads. The ads may be shown randomly or in a sequential fashion. What if the ads are of different sizes?

This script is a solution to all the above problems. This script can cycle images of different sizes on your site in a random or sequential order.

Extract the images directory and this file into the same directory and run the script for a demo.

<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<title>Javascript Image Rotater</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript">
<!--
// The order of display : True - Random / False - Sequential
var randomOrder = false;
// Default Width of the image (if not set individually)
var defaultWidth = 50;
// Default Height of the image (if not set individually)
var defaultHeight = 50;
// An array of the images to be rotated (Image Path[, Width of the Image[, Height of the Image]])
// If the width and height is not specified, the Default value specified above will be used
var arImg = new Array();
arImg[0] = ['images/1.gif'];
arImg[1] = ['images/2.gif', 100, 100];
arImg[2] = ['images/3.gif'];
arImg[3] = ['images/4.gif', 25, 25];
arImg[4] = ['images/5.gif'];

function rotateImage(){
    if(randomOrder){
        index = Math.floor(Math.random() * arImg.length);
    }else{
        var index = getCookie('rotate_image');
        index = index ? index : 0;
        index = ++index % arImg.length;
    }
    (img = document.getElementById('image_id')).src = arImg[index][0];
    img.width = (arImg[index][1]) ? arImg[index][1] : defaultWidth;
    img.height = (arImg[index][2]) ? arImg[index][2] : defaultHeight;
    setCookie('rotate_image', index);
}
/*
Functions for storing and retrieving cookies from my previous example
Check http://www.weberdev.com/get_example-4570.html
*/

function getCookie(name) {
    var sPos = document.cookie.indexOf(name + '=');
    var len = sPos + name.length + 1;
    if((!sPos) && (name != document.cookie.substring(0, name.length))){
        return null;
    }
    if(sPos == -1){
        return null;
    }
    var ePos = document.cookie.indexOf(';', len);
    if(ePos == -1) ePos = document.cookie.length;
    return unescape(document.cookie.substring(len, ePos));
}

function setCookie(name, value, expires, path, domain, secure){
    var today = new Date();
    if(expires){
        expires = expires * 1000 * 3600 * 24;
    }
    document.cookie = name+'='+escape(value) +
        ((expires) ? ';expires=' + new Date(today.getTime() + expires).toGMTString() : '') +
        ((path) ? ';path=' + path : '') +
        ((domain) ? ';domain=' + domain : '') +
        ((secure) ? ';secure' : '');
}
//-->
</script>
</head>

<body onload="rotateImage()">
<img src="images/1.gif" id="image_id" width="50" height="50" border="0" alt=""/>
</body>
</html>



This is a script that list all image files on a given directory, and displays the thumbnails nicely formated within an HTML table. It also make use of JavScript to open pop up windows when the users want to see the full photo.
Categories : Graphics, PHP, Complete Programs, Java Script
Random Image
Categories : Java Script, Graphics
JAVASCRIPT interface class to the eBusiness Charts generatation remote service.
Categories : Java Script, Graphics, Charts and Graphs
A ball is attached to your mouse cursor with an elastic cord!
Categories : Java Script, DHTML, Graphics
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
Zephyr: AJAX Based Framework for PHP5 Developers
Categories : PHP, AJAX, Frameworks, Java Script, Web Applications
AJAX XML HTTP Request - Compatible with almost browsers!
Categories : AJAX, HTTP, Java Script
javascript doesn't accept a fieldname with []
Categories : Java Script
Array values from javascript to php
Categories : PHP, Java Script, Arrays
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
Linked comboboxes with php-mysql & javascript
Categories : PHP, Java Script, Databases, MySQL
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
The toll booth
Categories : PHP, Java Script, Filesystem
MD5 secured login
Categories : PHP, Java Script, Authentication, Security
Bypassing Plugin / FLASH Activation
Categories : Java Script, Web Browsers, Security, Flash