...

View Full Version : I need help with something



Teal
02-08-2004, 05:16 PM
Currently I am creating a web site that is slightly more interactive than the average web site, tables that you can move around the screen, a sort of 3d thing...

I don't really need help with any of that what I need help with is something that should be quite simple but isn't, at least for me any way.

What I need is a script that contains a list of differing words the script would read these words then put a word into a text box randomly or in a series and then once you refreshed the page or pressed a button it would come up with a differing word.

Antoniohawk
02-08-2004, 05:40 PM
Try something like so:


<script language="JavaScript">

var word = new Array()

word[0] = "Hi";
word[1] = "my";
word[2] = "name";
word[3] = "is";
word[4] = "Fred";

var w = word.length;
var selectWord = Math.round(Math.random() * (w - 1));

function giveWord() {
document.write(word[selectWord]);
}
giveWord();
</script>

Teal
02-08-2004, 06:12 PM
Thank you Antoniohawk, however I have already done that, what I want to know is how do you put that random value into a word box.

for example:

<td class="PPRLabelText">Password&nbsp;</td>
<td><input type="text" name="wordbox" maxlength="16" class="PPRField" size="25" tabindex="2" autocomplete="ON"></td>

Willy Duitt
02-08-2004, 06:29 PM
Originally posted by Teal
Thank you Antoniohawk, however I have already done that, what I want to know is how do you put that random value into a word box.

Then change document.write(word[selectWord]);
To target your wordbox.

eg:
document.formName.wordbox.value = word[selectWord];

And use either an onload event handler or a button to populate the wordbox with the random value.

.....Willy

Garadon
02-08-2004, 07:01 PM
rounding the random function makes it unrandom, floor it instead



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum