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 53 54 55 56 57
| <html>
<head>
<script>
function LoadPays() {
var tabLPays;
tabLPays = new Array(
new Array("74","FRA - France"),
new Array("1","AFG - Afghanistan"),
...
new Array("239","ZWE - Zimbabwe")
);
return tabLPays;
}
/*
:) Fonction : fillSelectFromArray
:) Input : selectCtrl:nom du select,itemArray:les données,intPOptionVide=1 alors une ligne vide,strPValue
:) Output :
*/
function fillSelectFromArray(selectCtrl, itemArray, intPOptionVide,strPValue) {
var i, j, k, l;
l = 1;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null;
}
j = 0;
if (itemArray != null) {
// add new items
if (intPOptionVide==1){
selectCtrl.options[j] = new Option('','');
j++;
}
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][l]);
if (itemArray[i][0] != null) {
selectCtrl.options[j].value = itemArray[i][0];
if (itemArray[i][0] == strPValue) k = j;
}
j++;
}
//selectCtrl.options[k].selected = true;
}
}
</script>
</head>
<body>
Liste des pays <br />
<select id ="listepays" name="listepays">
</select>
<script>
var tabLAllPays = LoadPays();
var sel = document.getElementById('listepays');
fillSelectFromArray(document.getElementById('listepays'),tabLAllPays,1,'');
</script>
</body>
</html> |
Partager