Probleme fonction js

Résolu/Fermé
lwdu76 Messages postés 68 Date d'inscription samedi 16 janvier 2021 Statut Membre Dernière intervention 8 novembre 2022 - Modifié le 9 oct. 2022 à 12:35
 lwdu76 - 9 oct. 2022 à 14:34

bonjour, 

je voudrais faire une liste déroulante donc j'ai fait ceci en html et js mais elle ne fonctionne pas 

function liste_deroulante () {

    var list_selected = document.createElement("select");

    var list_cat = new Array ("abyssin", "american curl", "american shorthair", "american wirehair", "anatoli", "angora turc", "asian", "brume australianne", "balinais", "bengal", "bleu russe", "americain", "bobtail des kouriles", "bobtail japonais", "bombay", "brazilian shorthair", "british longhair", "british shorthair", "burmese", "burmilla", "californian rex", "californian spangled", "ceylan", "chartreux", "chantilly", "chausie", "colorpoint shortair", "cornish rex", "cymric", "devon rex", "donskoy", "european shortair", "exotic shortair", "german rex", "havana brown", "highlander", "highland fold", "himalayen", "khao manee", "korat", "laperm", "maine coon", "mandarin", "manx", "mau arabe", "mau égyptien", "minskin", "munchkin", "nebelung", "norvégien ou skogkatt", "ocicat", "ojos azules", "oriental shortair", "persan", "peterbald", "pixie-bob", "ragamuffin", "ragdoll", "sacré de bismanie", "safari", "savannah", "scottish fold", "selkirk rex", "serengeti", "seychellois", "siamois", "sibérien", "skookum", "snowshoe", "sokoké", "somali", "sphynx", "thaï", "tiffany", "tonkonois", "toyger", "turc de van", "ural rex", "york chocolat");

    for (var i = 0; i < list_cat.length; i++) {
        
        var option = document.createElement("option");
        
        option.innerHTML = list_cat[i];
        
        list_selected.appendChild(option);
    }
      
    liste_deroulante (document.body.appendChild(list_selected));
}
<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
  <body>
    <select name="select">
      <option value="" >Race list</option>
    </select>
<script src = "liste.js"></script>
  </body>
</html>

1 réponse

jordane45 Messages postés 38136 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 16 avril 2024 4 649
9 oct. 2022 à 13:32

Bonjour,

function liste_deroulante () {

  var list_selected = document.createElement("select");
  var list_cat = new Array ("abyssin", "american curl", "american shorthair", "american wirehair", "anatoli", "angora turc", "asian", "brume australianne", "balinais", "bengal", "bleu russe", "americain", "bobtail des kouriles", "bobtail japonais", "bombay", "brazilian shorthair", "british longhair", "british shorthair", "burmese", "burmilla", "californian rex", "californian spangled", "ceylan", "chartreux", "chantilly", "chausie", "colorpoint shortair", "cornish rex", "cymric", "devon rex", "donskoy", "european shortair", "exotic shortair", "german rex", "havana brown", "highlander", "highland fold", "himalayen", "khao manee", "korat", "laperm", "maine coon", "mandarin", "manx", "mau arabe", "mau égyptien", "minskin", "munchkin", "nebelung", "norvégien ou skogkatt", "ocicat", "ojos azules", "oriental shortair", "persan", "peterbald", "pixie-bob", "ragamuffin", "ragdoll", "sacré de bismanie", "safari", "savannah", "scottish fold", "selkirk rex", "serengeti", "seychellois", "siamois", "sibérien", "skookum", "snowshoe", "sokoké", "somali", "sphynx", "thaï", "tiffany", "tonkonois", "toyger", "turc de van", "ural rex", "york chocolat");

  for (var i = 0; i < list_cat.length; i++) {   
      var option = document.createElement("option");   
      option.innerHTML = list_cat[i];    
      list_selected.appendChild(option);
  }
  //on ajoute la liste dans le body de la page
  document.body.appendChild(list_selected)  
}


//On execute la fonction
liste_deroulante ();

0
lwdu76 Messages postés 68 Date d'inscription samedi 16 janvier 2021 Statut Membre Dernière intervention 8 novembre 2022
Modifié le 9 oct. 2022 à 13:57

il ne m'affiche pas la liste du tableau quand je la sélectionne

0
jordane45 Messages postés 38136 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 16 avril 2024 4 649 > lwdu76 Messages postés 68 Date d'inscription samedi 16 janvier 2021 Statut Membre Dernière intervention 8 novembre 2022
9 oct. 2022 à 13:54

Vide bien le cache de ton navigateur Internet avant de réessayer...

Regarder également dans la console javascript si il n'y a pas des messages d'erreur qui se seraient affichés...

Si ça ne fonctionne toujours pas pense bien à nous montrer l'intégralité de ton code que ça soit au niveau HTML ou JavaScript.

0
lwdu76 > jordane45 Messages postés 38136 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 16 avril 2024
9 oct. 2022 à 14:27

Il me qu"il ne peut pas lire la propriété appendchild

0
lwdu76 > jordane45 Messages postés 38136 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 16 avril 2024
9 oct. 2022 à 14:34

probleme resolu c'était parce que j'avais mis mon script js avant les balises html alors que c'est a la fin ;)

0