?
Solved

Cold Fusion and Javascript arrays

Posted on 2001-08-21
3
Medium Priority
?
200 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 400 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
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: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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