/    Sign up×
Community /Pin to ProfileBookmark

write random array value

can someone help me make this code work?

[code=php]
var rndArray = newArray(document.char.char00.value,
document.char.char01.value,
document.char.char02.value,
document.char.char03.value,
document.char.char04.value,
document.char.char05.value,
document.char.char06.value,
document.char.char07.value,
document.char.char08.value,
document.char.char09.value,
document.char.char10.value,
document.char.char11.value,
document.char.char12.value,
document.char.char13.value,
document.char.char14.value,
document.char.char15.value);

var rndNum = rnd(16)-1;
document.write(rndArray[rndNum.value]);

function rnd(){
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);}

function rand(number){return Math.ceil(rnd()*number);}
[/code]

I’m trying to display a random value from the array. It says “object expected” on the line the array is defined.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisAug 04.2004 — You have to make an onload function to build your array so that the form objects will exist.
Copy linkTweet thisAlerts:
@heavenly_blueauthorAug 04.2004 — this code is only called in another function after the page is loaded. i think the problem is that i'm not defining the array properly, can you define the array values with other variables?
Copy linkTweet thisAlerts:
@heavenly_blueauthorAug 04.2004 — OK after an hour of rearranging my code and trying new things i figured out the problem and it's the dumbest thing ever...

I had newArray() instead of new Array()
×

Success!

Help @heavenly_blue spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...