Template:KAISTRandom

From 2010.igem.org

(Difference between revisions)
Line 30: Line 30:
window.onload = function() {
window.onload = function() {
randomize("randomtable1");
randomize("randomtable1");
-
}
 
-
//-->
 
-
</script>
 
-
 
-
<script type="text/javascript">
 
-
<!--
 
-
Array.prototype.shuffle = function() {
 
-
  for (var i = 0; i < this.length; i++) {
 
-
    // Random item in this array.
 
-
    var r = parseInt(Math.random() * this.length);
 
-
    var obj = this[r];
 
-
 
-
    // Swap.
 
-
    this[r] = this[i];
 
-
    this[i] = obj;
 
-
  }
 
-
}
 
-
function randomize(tableID) {
 
-
var myTable = document.getElementById(tableID);
 
-
var myRows = new Array();
 
-
for (i=myTable.rows.length-1; i>=0; i--) {
 
-
var theRow = myTable.rows[i];
 
-
myRows.push(theRow);
 
-
theRow.parentNode.removeChild(theRow);
 
-
}
 
-
myRows.shuffle();
 
-
for (j=0; j<myRows.length; j++) {
 
-
myTable.appendChild(myRows[j]);
 
-
}
 
-
}
 
-
window.onload = function() {
 
-
randomize("randomtable2");
 
}
}
//-->
//-->

Revision as of 10:08, 21 June 2010