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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <script src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var CompteurLigne = 1;
//ajoute les lignes
$("#add_row").click(function () {
CompteurLigne++;
let markup = '<tr><td><input type="checkbox" name="record_'+CompteurLigne+'" class="record" ></td>';
markup += '<td><input type="text" placeholder="quantité" name="quantite_'+CompteurLigne+'" class="quantite">';
markup+= '</td><td><select type="text" name="designation_'+CompteurLigne+'"><?php $reponse = $bdd->query("SELECT * FROM kk"); while ($donnees = $reponse->fetch()){ echo "<option> $donnees[designation] </option>";}?></select></td>';
markup+= '<td><input type="text" placeholder="prix unitaire" name="prix_unitaire_'+CompteurLigne+'" class="prix_unitaire"></td>';
markup+= '<td><span name="pt_'+CompteurLigne+'" class="prix_taxe"></span></td></tr>';
$("form#form_trucs > table > tbody").append(markup);
Calcul_Prix_Taxe();
});
// Cherche et enleve les lignes selectionnees
$("#delete_row").click(function () {
$(".record:checkbox:checked").each(function () {
$(this).parents("tr").remove();
});
Calcul_Prix_Taxe();
});
$("#valider").click(function () {
Calcul_Prix_Taxe();
});
$("form#form_trucs > table > tbody").on("change", ".quantite, .prix_unitaire", function() {
Calcul_Prix_Taxe();
});
//Effectuer les calculs
function Calcul_Prix_Taxe() {
let Total_Taxes = 0;
$("form#form_trucs > table > tbody tr").each(function () {
let
Qte = parseInt( $(this).find(".quantite").val() ) || 0,
P_U = parseInt( $(this).find(".prix_unitaire").val() ) || 0,
P_T = Qte * P_U;
Total_Taxes += P_T;
$(this).find(".prix_taxe").html( (P_T).toString() );
});
$("#Tot_TX").html( (Total_Taxes).toString() );
}
//Rechercher le correspondant de lelement select avec AJAX
$('#id_select').on('change', function(){
var select_val = $(this).val();
$.ajax({
method: 'POST',
url: 'look.php',
data: { designation_1 : select_val }
dataType: 'html', // retour au format HTML
})
.success(function( html_retour ) {
$('#prix_unitaire_1').html( "Retour : " + html_retour );
});
});
});
</script> |
Partager