Bonjour à tous,
Voici une base de ce que j'ai fais : https://jsfiddle.net/zarkoffe/vksnoxhr/50/
Objectif : Sélectionner la référence d'un article (chargée depuis un bdd), et remplir le bon input en face en chargeant son nom (depuis une bdd aussi du coup).
Au code ci-dessus j'ai tenté de faire ceci, mais sans succès et sans erreur. Je clique sur 'Ajouter', et ma ligne ne s'ajoute pas.
et l'ajax:
Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 <td> <select type="text" class="form-control scope article_ref" style="width: 100%;" onchange="ref_to_rearticle(this.value)"> <option></option> <?php $list = $bdd->query('SELECT * FROM produit WHERE produit_contact = "'.$_SESSION['Contact_id'].'" ORDER BY `produit_ref` ASC'); while ($data = $list->fetch()) { ?> <option value="<?php echo $data['produit_ref']; ?>"><?php echo $data['produit_ref']; ?></option> <?php } $list->closeCursor(); ?> </select> </td> <td> <div id="article_refarticle"> <?php $article_ref = $_POST['article_ref'] ?? 'null'; $requete = $bdd->prepare(' SELECT * FROM produit WHERE produit_ref = :ref '); $stmt->bindValue(':ref', strtoupper($article_ref), PDO::PARAM_STR); $stmt->execute(); while ($donnees = $stmt->fetch(PDO::FETCH_ASSOC)) { echo "<input type=\"text\" value=\"{$donnees['produit_nom']}\" />"; } ?> </div> </td>
merci d'avance!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 function ref_to_rearticle(produit_ref) { $.ajax({ url: "modal_header/Actions/ajoutdevis.php", method: "POST", data: { article_ref: produit_ref } }) .done(function( retour_html ) { $("#article_refarticle").html( retour_html ); }) .fail(function() { alert( "error facture creation ajax" ); }); }
Partager