Click to See Complete Forum and Search --> : a javascript to randomize javascripts


Bixby
10-09-2003, 05:08 PM
I'm a complete javascript newbie, so bear with me!

I've got a couple scripts that pull source material from different places. I'd like to be able to rotate the sources.

Here's a page where I've tried to execute this (in the "Coming up on KMUW table), with no success.

http://www.kmuw.org/prototype/indexjavatest.html

I'd really appreciate it if someone could take a look at it and hopefully show me the error of my ways.

Thanks so much in advance.

Travman
10-09-2003, 05:51 PM
I have a Visual Javascript book with code for random generation of messages based on the number of possible messages. You'd have to change the code if you add more options:

function threeOptions(){
rand = Math.floor(Math.random() *3);
if (rand == 1) {
document.writeln("<script src=\"http://promos.npr.org/justice/justice.promo.js\"></script\>");
}
else if (rand == 2) {
document.writeln("<script src=\"http://promos.npr.org/justice/we/we.promo.js\"></script\>");
}
else {
document.writeln("<script src=\"http://promos.npr.org/justice/wwdtm/wwdtm.promo.js\"></script\>");
}
}

Would that work for you?