In comp.lang.javascript message <11*********************@i39g2000hsf.goo
glegroups.com>, Tue, 9 Jan 2007 10:30:42,
md*****@gmail.com posted:
>If I have a .js file filled with data like links. how do i access just
1 element [random] and bring it on my page
Make the file include function Random() from the FAQ, and
var MyStuff = [
"Link 0",
"Link 1",
// ...
"Link 9",
"Dummy" ]
and
function getRand(X) { return X[Random(X.length-1)] }
then in your page
SomeLink = getRand(MyStuff)
Include the .js file in the usual manner, as in <URL:
http://www.merlyn.
demon.co.uk/js-nclds.htm>.
You may prefer to have one .js file for the code and others for data.
"Dummy" was included for ease of editing; it allows all the links lines
to be of the same format. If you omit it, omit also -1.
It's a good idea to read the newsgroup and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.