Solved

Cold Fusion and Javascript arrays

Posted on 2001-08-21
3
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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