Recupérer la valeur d'un select

Résolu
jb25350 Messages postés 20 Date d'inscription jeudi 23 mars 2006 Statut Membre Dernière intervention 25 juillet 2021 - Modifié le 14 avril 2017 à 17:27
jb25350 Messages postés 20 Date d'inscription jeudi 23 mars 2006 Statut Membre Dernière intervention 25 juillet 2021 - 15 avril 2017 à 09:36
Bonjour à Tous et à Toutes,
Voici mon problème :

j'alimente un select avec une seconde table, mais j'aimerai récupérer la valeur du Select, actuellement je ne récupère que l'ID

1ère Table:
$reponse =$bdd->prepare('SELECT * FROM '.$vente_BDD.' ORDER BY id ASC');
   $reponse->bindParam(':id', $id, PDO::PARAM_INT);
   $reponse->bindParam(':numdossier', $numdossier, PDO::PARAM_STR);
   $reponse->bindParam(':nomvendeur', $nomvendeur, PDO::PARAM_STR);
   $reponse->bindParam(':departement', $departement, PDO::PARAM_STR);
   $reponse->bindParam(':localite', $localite, PDO::PARAM_STR);
   $reponse->bindParam(':prix', $prix, PDO::PARAM_INT);
   $reponse->bindParam(':typebien', $typebien, PDO::PARAM_STR);
   $reponse->execute(); 

Seconde table :
//---------------------------- Type de Bien ---------------------------------------------------
   $reponse05 =$bdd->prepare('SELECT id,typebiens,position FROM '.$typedebien_BDD.' ORDER BY position ASC');
   $reponse05->bindParam(':id', $id, PDO::PARAM_INT);
   $reponse05->bindParam(':position', $position, PDO::PARAM_INT);
   $reponse05->bindParam(':typebiens', $typebiens, PDO::PARAM_STR);   
   $reponse05->execute();

mon select :
<select name='typebien' id='typebien'style='width:180px;' > 
         <option selected=selected value='votrechoix'>Votre Choix</option>";         
         while ($donnees05 = $reponse05->fetch()) { 
          echo "<option value='".$donnees05['id']."' >".$donnees05['typebiens']."</option>";
         }
         $reponse05->closeCursor();
        echo" 
        </select>      
        <script language='Javascript'>
         <!--
         function change_valeur() {
         select = document.getElementById('typebien');
         choice = select.selectedIndex  // Récupération de l'index du <option> choisi
         typebien = select.options[choice].value; // Récupération du texte du <option> d'index 'choice'
         // -->
        </script>  


Merci pour votre Aide
A voir également:

2 réponses

jordane45 Messages postés 38135 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 13 avril 2024 344
14 avril 2017 à 20:35
Bonjour,

Ta question ne concerne pas le PHP (thème de ce forum) ... mais le JAVASCRIPT.
(je déplace ta question dans le bon forum ... )

Voici la solution

function change_valeur() {
         var select = document.getElementById('typebien');
         var choice = select.selectedIndex;
         var id = select.options[choice].value; 
         var text =  select.options[choice].value; 
}



bien entendu .. pour lancer la fonction js (je ne vois rien dans ton code pour le faire ...... ) tu peux mettre un onchange sur ton select

<select name='typebien' id='typebien'style='width:180px;' onchange="change_valeur();"> 

1
Rejoignez-nous