- - Code, Content, and Presentation
MichaelBluejay - 11:39 pm on Sep 29, 2012 (gmt 0)
names = ["Doe", "Ray", "Me"];
now = new Date();
seed = now.getSeconds();
ranNumber = Math.floor(Math.random(seed)*3);
document.getElementById('name').value = names[ranNumber];
(1) You don't need a function, since you want the script to run just once when the page loads.
(2) The first two lines make sure you get a random number every time.
(4) For that matter, it wouldn't hurt to change the id of the <input> to "nameField" or "name_" or something (and then change it in the script, too).
Brought to you by WebmasterWorld: http://www.webmasterworld.com