•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 332,576 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,114 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 353 | Replies: 1
![]() |
•
•
Join Date: Mar 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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());
<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());
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 327
Reputation:
Rep Power: 0
Solved Threads: 31
•
•
•
•
(trg = random(placearray.length); saying "object expected". can anyone point out my problem here?
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
~Mitch Ratcliffe
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- Starting a project in python (Game and quiz) (Python)
- serious problem..in online examination ..plz solve that as soon as possible (JavaScript / DHTML / AJAX)
- trying to point to an array (C++)
- Eek! (JavaScript / DHTML / AJAX)
- error checking of user input (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: HTML
- Next Thread: Help with Ajax toolkit drop downs


Linear Mode