Solved

Cold Fusion and Javascript arrays

Posted on 2001-08-21
3
191 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now