Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Help! How the heck do you get javascript links to randomize or rotate?
Old 06-27-2009, 09:40 AM Help! How the heck do you get javascript links to randomize or rotate?
Junior Talker

Posts: 3
Name: Alistair Keddie
Trades: 0
Hi, I'm very new to Javascript and I'm trying to figure out a way of getting these pieces of code to display either randomly or in rotation in one 'box' on my site rather than as a 'list' of boxes as they do now. Can anyone help me with this? Hope this makes sense! ) Thanks

<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=12125"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=12163"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=12144"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=12127"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=12123"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=12098"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=8128"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=7997"></script>
<script language="Javascript" src="http://box.jpgmag.com/story_badge.php?s=7916"></script>
bigalba is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-29-2009, 08:33 PM Re: Help! How the heck do you get javascript links to randomize or rotate?
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
Try this:
Code:
<script type="text/javascript">
var stories = [12125,12163,12144,12127,12123,12098,8128,7997,7916];
var randomIndex = Math.floor(Math.random()*stories.length);
var story = stories[randomIndex];

document.write('<scr'+'ipt type="text/javascript" src="http://box.jpgmag.com/story_badge.php?s=' + story + '"></scr'+'ipt>');
</script>
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 06-30-2009, 06:24 AM Re: Help! How the heck do you get javascript links to randomize or rotate?
Junior Talker

Posts: 3
Name: Alistair Keddie
Trades: 0
Genuis, works like a charm! Thanks very much for that Paul and how exactly do I get you that beer? ) I think this bit of code would be really useful for the members of JPG Magazine to use for linking up their photography articles on their own sites. Would you mind if I passed it on, with full credits to yourself of course? I've added a credit and link back on my own site under your working code! Thanks again, Al
bigalba is offline
Reply With Quote
View Public Profile
 
Old 06-30-2009, 01:49 PM Re: Help! How the heck do you get javascript links to randomize or rotate?
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
Glad to help, feel free to pass it along.

I'm in the Bay area and travel quite a bit for work so, if we run into each other, I'll take you up on the beer
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 06-30-2009, 02:09 PM Re: Help! How the heck do you get javascript links to randomize or rotate?
Junior Talker

Posts: 3
Name: Alistair Keddie
Trades: 0
Well, if your ever in Scotland or Zagreb look me up
cheers mate

al
bigalba is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help! How the heck do you get javascript links to randomize or rotate?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39329 seconds with 12 queries