Solved

Cold Fusion and Javascript arrays

Posted on 2001-08-21
3
196 Views
Last Modified: 2013-12-24
I have a rotating ad banner system that randomizes the ID for each refresh of the page... It takes a range of numbers, and selects a random number, between 1 and the maximum recordcount. The only problem is that if records are deleted, it includes that ID in the range.

How can I randomize within a set number of EXISTING records?

EG:

ID
1
2
3
4
5
6
7
9
25
33

What will happen, is that it will randomize between 1 and 33... Eventually, it will try to display the banner with the ID of 10... However there is no banner there with that ID... How can I avoid this?
0
Comment
Question by:webmaster256
3 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 100 total points
ID: 6410892
You should create a JavaScript Array using the record ID's retrieved.
var myArray = new Array();
myArray = { 1, 2,3,4,5,6,7,9,25,33 }; // This is built via ColdFusion query

Now randomize based on the array size:
var rnd = Math.floor(Math.random() * myArray.length);

Now display the banner of the number generated:
myArray[rnd];
0
 
LVL 5

Expert Comment

by:Yog
ID: 6411028
or just get the CF_RGrabber custom tag and use..
0
 

Author Comment

by:webmaster256
ID: 6507628
Thank you very much!!! Sorry it took so long for me to get back to you on this...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question