i have a web page with an array of text messages which i want to 1) shuffle, and 2) scroll. first the shuffle part. right now i can scroll one random message per refresh of page. i want to shuffle the list and then change the scroll function to display all messages in random order. here is page now:

<html>
<head>
<script language="JavaScript" type="text/javascript">
var msg = new Array(5);
msg[0]  = "First Message"
msg[1]  = "Second Message"
msg[2]  = "Third Message"
msg[3]  = "Fourth Message"
msg[4]  = "Fifth Message."
 var count = 0;
 var i = 0;
 any = Math.floor(msg.length * Math.random());
 while (i < 60) { i++; msg[any] = " " + msg[any]; }
function msgScroll() {
 document.scroll.msg.value = msg[any].substring(count, msg[any].length);
 count++;
 if (msg[any].length == count) { count = 0; }
 window.setTimeout("msgScroll()", 150);
 }
window.onload=msgScroll;
</script>
</head>
<body>
<form name="scroll">
  <p align="center">
  <font color="#0000FF">
  <input name="msg" size="125" style="border:0px solid; font-family:georgia; font-weight:700"></font></p>
</form>
</body>
</html>

i found following code to effect the shuffle but before i could customize to my page i get an error on 9th line: (trg = random(placearray.length); saying "object expected". can anyone point out my problem here?

arraythang = ["narf", "nood", "philbin", "twink", "snoogans"];
placearray = new Array();
newthang = new Array();
for (a=0; a<arraythang.length; a++) {
        placearray.push(a);
}
for (a=0; a<arraythang.length; a++) {
        do {
                trg = random(placearray.length);
                newplace = placearray[trg];
        } while (arraythang[a] == arraythang[newplace] && a != arraythang.length-1);
        placearray.splice(trg, 1);
        if (arraythang[a] != arraythang[newplace]) {
                newthang.push(arraythang[newplace]);
        } else {
                newthang.unshift(arraythang[newplace]);
        }
}
trace (arraythang.toString());
trace (newthang.toString());

(trg = random(placearray.length); saying "object expected". can anyone point out my problem here?

it Math.random()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.