En lille rettelse:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1"><title>Ingen titel</title>
</head><body>
<script type="text/javascript">
sorts={"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"a":10,"b":11,"c":12,"d":13,"e":14,"f":15,"g":16,"h":17,"i":18,"j":19,"k":20,"l":21,"m":22,"n":23,"o":24,"p":25,"q":26,"r":27,"s":28,"t":29,"u":30,"v":31,"w":32,"x":33,"y":34,"z":35,"æ":36,"ø":37,"å":38}; // Beregning af tals værdi i række placering
function sorter_fornavn(a,b){
var tala=talb=0;
for(i=0,i2=a[1].length;i<i2;i++){
tala+=(tn=sorts[a[1].charAt(i).toLowerCase()]/(40*i+1))?tn:0;
}
for(i=0,i2=b[1].length;i<i2;i++){
talb+=(tn=sorts[b[1].charAt(i).toLowerCase()]/(40*i+1))?tn:0;
}
return tala-talb;
}
function sorter_efternavn(a,b){
var tala=talb=0;
for(i=0,i2=a[2].length;i<i2;i++){
tala+=(tn=sorts[a[2].charAt(i).toLowerCase()]/(40*i+1))?tn:0;
}
for(i=0,i2=b[2].length;i<i2;i++){
talb+=(tn=sorts[b[2].charAt(i).toLowerCase()]/(40*i+1))?tn:0;
}
return tala-talb;
}
function sorter_brugernavn(a,b){
var tala=talb=0;
for(i=0,i2=a[0].length;i<i2;i++){
tala+=(tn=sorts[a[0].charAt(i).toLowerCase()]/(40*i+1))?tn:0;
}
for(i=0,i2=b[0].length;i<i2;i++){
talb+=(tn=sorts[b[0].charAt(i).toLowerCase()]/(40*i+1))?tn:0;
}
return tala-talb;
}
var myFriend = new Array();
myFriend[32] = new Array('Hans1', 'Hans', 'Hansen', 'male', 'Nordjylland', 3, 1);
myFriend[65] = new Array('Mikkel7', 'Mikkel', 'Andersen', 'male', 'Østjylland', 3, 1);
myFriend[40] = new Array('Claus4', 'Claus', 'Clausen', 'male', 'Østjylland', 1, 1);
window.onload=function(){
myFriend.sort(sorter_fornavn);
test();
}
function test(){
document.getElementById("test").firstChild.nodeValue=myFriend;
}
</script>
<div id="test">Resultat her</div>
<b onclick="myFriend.sort(sorter_fornavn);test();">Sorter efter fornavn</b><br><br>
<b onclick="myFriend.sort(sorter_efternavn);test();">Sorter efter fornavn</b><br><br>
<b onclick="myFriend.sort(sorter_brugernavn);test();">Sorter efter brugernavn</b>
</body></html>