Template:KAISTRandom

From 2010.igem.org

(Difference between revisions)
(New page: <html> <head> <script type="text/javascript"> <!-- Array.prototype.shuffle = function() { for (var i = 0; i < this.length; i++) { // Random item in this array. var r = parseInt(...)
Line 29: Line 29:
}
}
window.onload = function() {
window.onload = function() {
-
randomize("randomtable");
+
randomize("randomtable1");
}
}
//-->
//-->
</script>
</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");
 +
}
 +
//-->
 +
</script>
 +
</head>
</head>
</html>
</html>

Revision as of 10:07, 21 June 2010