Javascript variable undefined

Bonjour,

J'ai le code suivant en javascript qui me permet de créer dynamiquement un bouton select en fonction d'une liste.
Cela fonctionne bien, sauf, que je souhaite avoir une valeur affichée, et une valeur renvoyée pour l'option choisie. Pour la valeur affichée this[i] pas de problème, par contre pour this.tmp[i] (la valeur a renvoyée), j'ai un "undefined" pour toute les valeurs. J'ai retourné le problème dans tous les sens, je ne trouve pas de solution.

Merci de votre aide !

mon code :

function CreerListe(nom, hauteur, largeur) {
this.nom=nom; this.hauteur=hauteur; this.largeur=largeur;
this.search="";
this.tmp="";
this.nb=0;
this.Add=AjouterItem;
this.Adde=AjouterItem2;
this.Afficher=AfficherListe;
this.MAJ=MAJListe;
}

function AjouterItem(item) {
this[this.nb]=item
this.nb++;
}

function AjouterItem2(item) {
this.tmp[this.nb]=item;
this.nb++;
}

function AfficherListe() {
if (document.layers) {
var Z="<SELECT name="+this.nom+" size="+this.hauteur+">";
} else {
var Z="<SELECT name="+this.nom+" size="+this.hauteur+" style='width:"+this.largeur+"'>";
}
for (var i=0; i<this.nb; i++) {
Z+="<OPTION value=\""+this.tmp[i]+"\">"+this[i]+"</OPTION>"
i++
}
Z+="</SELECT>"
document.write(Z);
}
Configuration: Windows XP
Firefox 3.5.3

1 réponse

  1. Salut,

    Peut-être...
    function CreerListe(nom, hauteur, largeur) {
    this.nom=nom;
    this.hauteur=hauteur;
    this.largeur=largeur;
    this.search="";
    this.tmp="";
    this.nb=20;
    this.Add=AjouterItem;
    this.Adde=AjouterItem2;
    this.Afficher=AfficherListe(nom);
    }
    
    function AjouterItem(item) {
    this[this.nb]=item
    this.nb++;
    }
    
    function AjouterItem2(item) {
    this.tmp[this.nb]=item;
    this.nb++;
    }
    
    function AfficherListe(nom) {
    if (document.layers) {
    var Z="<SELECT name="+nom+" size="+this.hauteur+">";
    } else {
    var Z="<SELECT name="+nom+" size="+this.hauteur+" style='width:"+this.largeur+"'>";
    }
    for (var i=0; i<this.nb; i++) {
    Z+="<OPTION value=\""+this.tmp[i]+"\">"+nom+"</OPTION>"
    i++
    }
    Z+="</SELECT>"
    document.write(Z);
    }
    


    0
    1. Merci pour ta réponse Wardog, mais ça ne marche pas ...

      Je n'ai toujours pas trouvé, une autre tentative ?
      0