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
Printable View
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
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:
Code:<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.
Thanks a lot man :)
No Problem