Forum Moderators: open
HTML:
<script type="text/javascript">galleryLink('news');</script>
JavaScript:
var news = new Array();
news[0] = '946,News Highlights';
news[1] = '82394,Weird News Highlights';
news[2] = '948,Top Entertainment';
news[3] = '179347,News Photos';
news[4] = '947,Sports Highlights';
function galleryLink(category) {
do {
var randomGallery = Math.floor(Math.random()*10);
}
while(randomGallery>=category.length);
}
However you have a problem in the line
var randomGallery = Math.floor(Math.random()*10);
I think you want to change that * 10 with the catlength, otherwise
1) It will sometimes exceed the size of the array (if it is smaller than 10).
2) Will never get items in the array that are beyond the 10th item.
Then you can get rid of that while loop as well, as I think all you are doing there is discarding ones that are out of range.
HTML
<script type="text/javascript">p2Galleries('news');</script>
JavaScript
var news = new Array();
news[0] = '946,News Highlights';
news[1] = '82394,Weird News Highlights';
news[2] = '948,Top Entertainment';
news[3] = '179347,News Photos';
news[4] = '947,Sports Highlights';
function p2Galleries(category) {
var catlength = window[category].length;
var randomGallery = Math.floor(Math.random()*catlength);
var gallery = window[category][randomGallery].split(',');
var number = gallery[0];
var title = gallery[1];
document.write('<a href="javascript:open_photo_popup(' + number + ')">' + title + '</a>');
}