jb25350
Messages postés21Date d'inscriptionjeudi 23 mars 2006StatutMembreDernière intervention25 juillet 2021
-
Modifié le 14 avril 2017 à 17:27
jb25350
Messages postés21Date d'inscriptionjeudi 23 mars 2006StatutMembreDernière intervention25 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:
Récupérer la valeur d'un select javascript
Recuperer la valeur d'un select js - Meilleures réponses
jordane45
Messages postés37506Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention29 mai 2023341 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
jb25350
Messages postés21Date d'inscriptionjeudi 23 mars 2006StatutMembreDernière intervention25 juillet 2021 15 avril 2017 à 09:36
Bonjour à Tous,
Merci infiniment Jordane,
Je pensais récupérer la valeur avec un $_POST d'ou mon message dans PHP, désolé
Tu m'as démontré que mon code JavaScript était inutile(pas d'appel)
J'ai donc naturellement utiliser ta solution et .......CA MARCHE !!!
Juste une précision, comme j'ai d'autres champs qui sont du même bois, puis-je utiliser cette fonction comme ci-dessous ?
<script language='Javascript'>
//<![CDATA[
function change_valeur() {
var select = document.getElementById('typebien');
var choice = select.selectedIndex;
var id = select.options[choice].value;
var typebien = select.options[choice].value;
}
on change_valeur02() {
var select = document.getElementById('typebien');
var choice = select.selectedIndex;
var id = select.options[choice].value;
var cuisine = select.options[choice].value;
}
function change_valeur03() {
var select = document.getElementById('typebien');
var choice = select.selectedIndex;
var id = select.options[choice].value;
var chauffage = select.options[choice].value;
}
function change_valeur04() {
var select = document.getElementById('typebien');
var choice = select.selectedIndex;
var id = select.options[choice].value;
var slogan = select.options[choice].value;
}
//]]>
</script>
Merci à toi Jordane pour tes connaissances, ta rapidité, et ta disponibilité, Bravo
Bernard