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
|
<head>
<script ...>
var liste = new Array();
function MonObjet(id, libelle, comment, valeur)
{
this.id = id;
this.libelle = libelle;
this.comment = comment;
this.valeur = valeur;
}
function ajouterValeur(id, libelle, comment, valeur)
{
liste[liste.length] = new MonObjet(id, libelle, comment, valeur);
}
...
function creerCombo()
{
var combo = document.getElementById("maCombo");
if ( combo == null ) return;
for ( var i = 0; i < liste.length; i++ )
{
combo.options[combo.options.length] = new Option( liste[i].libelle, liste[i].id);
}
}
function afficherInfo(id)
{
for ( var i = 0; i < liste.length; i++ )
{
if ( liste[i].id == id )
{
alert("Mes infos :\n- " + liste[i].comment + "\n- " + liste[i].valeur);
return;
}
}
}
</script>
</head>
<body>
...
<select name="maCombo" id="maCombo" onchange="afficherInfo(this.value)">
</select> |
Partager