[Formulaire] Changer les options d'un <select>

Changer les options d'un <select> [Formulaire] - HTML/CSS - Programmation

Marsh Posté le 10-07-2005 à 02:48:17    

J'arrive à changer le texte (c-à-d la valeur) d'un <input> texte, bouton... mais je n'arrive pas à changer le texte qui apparaît dans un <select>. Ce qui serait parfait, c'est si je pouvais faire rentrer une liste de chaînes dans un <select> sans dialoguer avec le serveur, uniquement avec un code client (comme du JavaScript).

Reply

Marsh Posté le 10-07-2005 à 02:48:17   

Reply

Marsh Posté le 10-07-2005 à 15:02:01    

Pas de réponse ? Si je peux simplement faire disparaître certaines possibilités, ça me suffit. J'attends vos idées !

Reply

Marsh Posté le 10-07-2005 à 15:14:34    

ya pas de texte dans les <select>, le texte est dans les <option> contenues dans les <select> [:spamafote]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 10-07-2005 à 15:39:48    

Oui, ça je sais. Tu saurais désactiver certains <option> ?

Reply

Marsh Posté le 10-07-2005 à 15:42:57    

tu les supprimes [:spamafote]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 10-07-2005 à 15:49:32    

Ouaaaa !!! J'y avais pas pensé !!! Le problème c'est : Comment tu les supprimes ?
 
Je m'explique : j'ai ceci :

<select>
    <option>Bonjour</option>
    <option>Salut</option>
    <option>Au-revoir</option>
</select>

J'aimerais qu'en faisant une action sur la page (par exemple cliquer sur un bouton) ça enlève le choix "Salut", pour ne garder que "Bonjour" et "Au-revoir". Tu sais comment faire ça ?

Reply

Marsh Posté le 10-07-2005 à 15:51:01    

e-miel a écrit :

Ouaaaa !!! J'y avais pas pensé !!!


J'avais remarqué [:spamafote]

Citation :

Tu sais comment faire ça ?


oui [:spamafote]  


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 10-07-2005 à 15:53:31    

Tu n'as pas répondu à ma question : "Comment tu les supprimes ?" Ecris-moi simplement le code JavaScript pour faire ça.

Reply

Marsh Posté le 10-07-2005 à 16:01:30    

Non.
 
par contre je peux te donner la méthode pour le faire

removeChild()
 Removes a child node from an element  
 
x.removeChild(y)
Remove child y of node x.


Message édité par masklinn le 10-07-2005 à 16:01:46

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 10-07-2005 à 16:07:51    

Ok, je vais tester ça. Merci !

Reply

Marsh Posté le 10-07-2005 à 16:07:51   

Reply

Marsh Posté le 10-07-2005 à 16:21:07    

Je n'y arrive pas. Voici ce que j'ai fait :

<select id=sel>
    <option>Bonjour</option>  
    <option id=sal>Salut</option>  
    <option>Au-revoir</option>  
</select>
 
<script>
    document.getElementById('sel').removeChild(document.getElementById('sal'))
</script>

Et toi, tu écrirais quoi ?

Reply

Marsh Posté le 10-07-2005 à 16:25:17    

Ah, ça marche !
Il suffisait de quitter et de relancer le navigateur, les "Refresh" ne suffisaient pas. Merci pour la fonction, elle me sera très utile !

Reply

Marsh Posté le 10-07-2005 à 16:43:05    

http://www.quirksmode.org/?/dom/w3c_core.html


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed