Solved

Cold Fusion and Javascript arrays

Posted on 2001-08-21
3
195 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 VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IIS 404 Error on website Automatic Redirect to /help 5 57
System Analysis 5 58
site launch date and last modified date 3 93
Moving web servers into a DMZ? 3 56
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

770 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