Hi guys
I wonder if you can help me, if I have a list of items
and there can be between 15 and 100 of them listed, is it possible for that list to be randomly sorted on each page load?Code:<li>item</li> <li>item2</li> and so on....
Thanks
Hi guys
I wonder if you can help me, if I have a list of items
and there can be between 15 and 100 of them listed, is it possible for that list to be randomly sorted on each page load?Code:<li>item</li> <li>item2</li> and so on....
Thanks
1st rule of web development - use Firefox and Firebug
2nd rule - see the first rule
--
I like Smilies
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> </head> <body> <ul id="tst"> <li>tom</li> <li>****</li> <li>harry</li> </ul> <script type="text/javascript"> /*<![CDATA[*/ function RandomList(id){ var ul=document.getElementById(id); var lis=ul.getElementsByTagName('*') for (var ary=[],z0=0;z0<lis.length;z0++){ if (lis[z0].parentNode==ul){ ary.push(lis[z0]); } } ary.shuffle(); for (var z1=0;z1<ary.length;z1++){ ul.appendChild(ary[z1]); } } Array.prototype.shuffle=function(){ for (var r,t,z0=0;z0<this.length;z0++){ r=Math.floor(Math.random()*this.length); t=this[z0]; this[z0]=this[r]; this[r]=t; } } RandomList('tst') /*]]>*/ </script> </body> </html>
Vic
God Loves You and will never love you less.
http://www.vicsjavascripts.org/Home.htm
If my post has been useful please donate to http://www.operationsmile.org.uk/
wow thanks for such a quick reply with a solution, please know it is greatly appreciated
Cheers
1st rule of web development - use Firefox and Firebug
2nd rule - see the first rule
--
I like Smilies
Bookmarks