Click to See Complete Forum and Search --> : Need help with basic Javascript thing
Lannn
Aug 29th, 2003, 04:08 PM
I want to put a script on an HTML page that will show up a random text or number from a list.
Like, whenever I reload the page, a random text appears on the page or something like that.
Thanks :D
RealisticGraphics
Aug 29th, 2003, 07:14 PM
Something like this should work. It could probably be cleaned up a bit, but you should be able to get the picture. Just copy and past the code into a new HTML file to give it a try:
<script langauge="JavaScript">
var aList = new Array();
var ALC = 0;
aList[ALC++] = "I Feel Great"
aList[ALC++] = "I Feel Sick"
aList[ALC++] = "I Feel Stupid"
function ShowRndMsg(){
var sMsg
var iRnd = Math.round(Math.random() * (ALC-1))
sMsg = aList[iRnd];
return sMsg;
}
</script>
This is some test text<br><br>
<script language="JavaScript">
document.writeln("How I Feel: <b>" + ShowRndMsg() + "</b>");
</script>
<br><br>
This is some more test text.
Lannn
Aug 30th, 2003, 10:25 PM
Thanks a lot man :)
RealisticGraphics
Aug 31st, 2003, 09:35 AM
No Problem
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.