Partage
  • Partager sur Facebook
  • Partager sur Twitter

Remplir un select en fonction d'un autre

Sujet résolu
12 septembre 2019 à 21:20:29

Bonjour,

J'ai un formulaire avec 2 select.

Le 2 select doit se remplir dynamiquement en fonction du choix du premier select.

Comment je peux faire pour faire ca car je ny arrive pas.

Merci de votre aide.

<table border="0" style="margin:auto; margin-top: 3%; margin-bottom: 2%;">

                        <tr>
                            <td><b>Type:</b></td><td>
                                <select  name="select_type" style="" onchange="genere_parametre(this)">
                                    <option></option>
                                    <option value="materiel_d_inspection">Materiel d'inspection</option>
                                    <option value="obturation">Obturation</option>
                                    <option value="rehabilitation">Réhabilitation</option>
                                </select>
                            </td>

                        </tr>

                    </table>


                    <script>
                        function genere_parametre(select_type)
                        {
                            var chosed = select_type.value;

                            if (chosed == 'materiel_d_inspection')
                            {
                                // generer un select specifique
                            }

                            else if (chosed == 'obturation')
                            {
                                // generer un autre select specifique
                            }

                            else if (chosed == 'rehabilitation')
                            {
                                // generer encore un autre select specifique
                            }
                        }
                    </script>





-
Edité par Jobard91 12 septembre 2019 à 21:23:11

  • Partager sur Facebook
  • Partager sur Twitter
La connaissance ne vaut que si elle est partagée.
13 septembre 2019 à 8:41:09

Bonjour,

Quelque chose comme ça peut être ?

<select name="select_type" onchange="select_changed(this);">
   <option></option>
   <option value="materiel_d_inspection">Materiel d'inspection</option>
   <option value="obturation">Obturation</option>
   <option value="rehabilitation">Réhabilitation</option>
</select>

<select name="select_materiel_d_inspection" style="display: none;">
   <option>1</option>
   <option>2</option>
   <option>3</option>
   <option>4</option>
</select>

<select name="select_obturation" style="display: none;">
   <option>5</option>
   <option>6</option>
   <option>7</option>
   <option>8</option>
</select>

<select  name="select_rehabilitation" style="display: none;">
   <option>9</option>
   <option>10</option>
   <option>11</option>
   <option>12</option>
</select>

<script>
function select_changed(_this) {
   document.getElementsByName('select_materiel_d_inspection')[0].style.display = 'none';
   document.getElementsByName('select_obturation')[0].style.display = 'none';
   document.getElementsByName('select_rehabilitation')[0].style.display = 'none';
   if(_this[_this.selectedIndex].value)
      document.getElementsByName('select_' + _this[_this.selectedIndex].value)[0].style.removeProperty('display');
};
</script>



  • Partager sur Facebook
  • Partager sur Twitter
13 septembre 2019 à 17:32:29

@totomaso nickel merci
  • Partager sur Facebook
  • Partager sur Twitter
La connaissance ne vaut que si elle est partagée.