NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Javascript Question

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 11-20-2007, 10:42 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Aug 2007
Posts: 75
travinb is an unknown quantity at this point
 



Javascript Question


Hi,

I wanted to know how to make an image rotator (with links) through javascript..is it possible to make one?

Basically every time the page is refreshed I want a new image with its link to come in the others place..

In the hope that I am not asking for too much..and looking for some really helpful tips...

thanks..
__________________
The Unneglectable Blog| FinanceJargon.com |NasCarSchedule.Info
|financeadvisor.co.in| budgethotelsbeijing.com | researchelp.com
travinb is offline  
Old 11-20-2007, 12:12 PM   #2 (permalink)
NamePros Regular
 
Palyriot's Avatar
Join Date: Jul 2004
Location: Seattle, Wa
Posts: 596
Palyriot is a jewel in the roughPalyriot is a jewel in the roughPalyriot is a jewel in the rough
 



I don't know much about JS, but it is possible in PHP and actually better.

PHP Code:
<?php

$imageList 
= array("pic1""pic2""pic3""pic4");

echo 
'<img src="'.$imageList[array_rand($imageList)].'">';

?>
This takes a random picture from the array. Just change the filenames under pic1, pic2, pic3, pic4.
????: NamePros.com http://www.namepros.com/programming/397906-javascript-question.html



PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=397906

$extAllowed 
= array("jpg""gif""png""JPG""GIF""PNG");

$imageDir 'img/';

$dirConn opendir($imageDir);
while (
$file readdir($dirConn)) {
     
$ext explode("."$file);
    if (
in_array($ext[1], $extAllowed)) {
        
$imageList[] = $file;
    }
}
closedir($imageDir);

echo 
'<img src="'.$imageDir.'/'.$imageList[array_rand($imageList)].'">';

?>
This one takes a random file from a directory. Just change the $imageDir variable to the folder that has your pictures.


Of course, these files are all shown randomly and not in any order. If you needed to do this in order, you would need to have some kind of counter in either a file or database keeping track of what picture was shown last.
Palyriot is offline  
Old 11-21-2007, 07:32 AM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Aug 2007
Posts: 75
travinb is an unknown quantity at this point
 



Thanks Derek...
I wouldn't need a counter and random images are just fine...
My only issue is will I be able to hyperlink the images?
Is there someway that can be added to the picture..

Thanks for the help.. this is really cool though perhaps not what I am looking for...

or else is there anyway I can rotate php files instead of images.. I can then include the images with their links to within those files.. as in ad1.php, ad2.php instead of pic1 pic2...
__________________
The Unneglectable Blog| FinanceJargon.com |NasCarSchedule.Info
|financeadvisor.co.in| budgethotelsbeijing.com | researchelp.com
travinb is offline  
Old 11-21-2007, 09:37 AM   #4 (permalink)
Joe
Senior Member
Join Date: Oct 2005
Location: Kent ~ U.K.
Posts: 3,209
Joe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud ofJoe has much to be proud of
 


Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
PHP Code:
<?php

$extAllowed 
= array("jpg""gif""png""JPG""GIF""PNG"); // this is the list of recognised file extensions (without the .)

$imageDir 'img/'// the folder in which all the images are

$dirConn opendir($imageDir);
while (
$file readdir($dirConn)) {
     
$ext explode("."$file);
    if (
in_array($ext[1], $extAllowed)) { // checking if the loaded file's extension is in the list of allowed extensions
????: NamePros.com http://www.namepros.com/showthread.php?t=397906
        
$imageList[] = $file;
    }
}
closedir($imageDir);

echo 
'<img src="'.$imageDir.'/'.$imageList[array_rand($imageList)].'">'// display the image on the page.

?>
That is it commented slightly to help you understand.

To rotate php files, merely change
PHP Code:
$extAllowed = array("jpg""gif""png""JPG""GIF""PNG");
AND
echo 
'<img src="'.$imageDir.'/'.$imageList[array_rand($imageList)].'">'
to
????: NamePros.com http://www.namepros.com/showthread.php?t=397906
PHP Code:
$extAllowed = array("PHP");
AND
include 
$imageList[array_rand($imageList)]; 
If this is the case, you might want to rename some of the variables appropriately.

Joe
__________________
Myself and "JackHeskett" are no longer associated with FusedHosting.net. Please pipe all PMs to admin [at] fusedhosting.net.
Last edited by TheArbiter; 11-21-2007 at 10:10 AM. Reason: typo
Joe is offline  
Old 11-21-2007, 12:32 PM   #5 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
PHP Code:
<?php

/**
 * Danltn | http://danltn.com
 * No warranty is given to code used
 */

$imgs = array(
"pic1.gif" => "http://google.com",
????: NamePros.com http://www.namepros.com/showthread.php?t=397906
"pic2.gif" => "http://msn.com",
"pic3.gif" => "http://example.com",
);

$image array_rand($imgs);
$url $imgs[$image];

echo 
"<a href='$url'><img src='$image' border='0'></a>";

?>
Daniel is offline  
Old 11-21-2007, 09:55 PM THREAD STARTER               #6 (permalink)
NamePros Member
Join Date: Aug 2007
Posts: 75
travinb is an unknown quantity at this point
 



Thanks guys..this is great
will surely work with these now.. and will get back to you on this..
__________________
The Unneglectable Blog| FinanceJargon.com |NasCarSchedule.Info
|financeadvisor.co.in| budgethotelsbeijing.com | researchelp.com
travinb is offline  
Old 11-21-2007, 11:52 PM   #7 (permalink)
NamePros Regular
 
Palyriot's Avatar
Join Date: Jul 2004
Location: Seattle, Wa
Posts: 596
Palyriot is a jewel in the roughPalyriot is a jewel in the roughPalyriot is a jewel in the rough
 



No problem travinb. You got it perfect Danltn. Thanks for the assist.
Palyriot is offline  
Old 11-22-2007, 12:01 AM   #8 (permalink)
NamePros Legend
 
weblord's Avatar
Join Date: Dec 2005
Location: Philippines - www.Nabaza.com
Posts: 19,785
weblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatnessweblord Has achieved greatness
 


Autism Protect Our Planet
since you want javascript
http://free-javascript.blogspot.com/...e-rotator.html

Originally Posted by travinb
Hi,

I wanted to know how to make an image rotator (with links) through javascript..is it possible to make one?

Basically every time the page is refreshed I want a new image with its link to come in the others place..

In the hope that I am not asking for too much..and looking for some really helpful tips...

thanks..
__________________
Nabaza.com - Amaia
weblord is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:30 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger