1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<script type="text/javascript">
<!--
var aVilles = new Array(
{id:1, cp:'72000', nom:'Le Mans'},
{id:2, cp:'50470', nom:'La Glacerie'},
{id:3, cp:'68130', nom:'Altkirch'},
{id:4, cp:'72190', nom:'Sargé-lès-le-Mans'},
{id:5, cp:'72190', nom:'Coulaines'},
{id:6, cp:'61000', nom:'Alençon'},
{id:7, cp:'68640', nom:'Riespach'},
{id:8, cp:'92170', nom:'Vanves'},
{id:9, cp:'75016', nom:'Paris'},
{id:10, cp:'44405', nom:'Rezé'},
{id:11, cp:'61500', nom:'Sées'});
// tri du tableau par rapport au contenu du premier élément du second niveau
function tri(a, b) {
return ( a[0] < b[0] ) ? -1 : 1;
if( a[0] === b[0] ) return 0;
}
var aVillesByCP = new Array();
var aVillesByNom = new Array();
for(key in aVilles) {
aVillesByCP.push(new Array(
aVilles[parseInt(key)].cp,
aVilles[parseInt(key)].id,
aVilles[parseInt(key)].nom
));
aVillesByNom.push(new Array(
aVilles[parseInt(key)].nom,
aVilles[parseInt(key)].id,
aVilles[parseInt(key)].cp
));
}
aVillesByCP.sort(tri);
aVillesByNom.sort(tri);
//-->
</script>
</head>
<body>
</body>
</html> |
Partager