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 78 79 80 81 82 83
| <script>
function CalculPanier(NbrProduit) {
var nbr1 = NbrProduit;
var nbr2 = Number(2);
var total = (Number(nbr1) * Number(nbr2));
document.getElementById("totaldon").innerHTML = total;
}
function Produit(id, reference, designation, prix) {
this.id= id;
this.reference= reference;
this.prix= prix;
this.designation= designation;
this.toString= function() {
return this.reference + " " + designation + " "+ prix;
}
}
var catalogue= new Array();
catalogue.push(new Produit(1, "ref 1", "ordinateur", 800));
catalogue.push(new Produit(2, "ref 2","souris", 20.45));
catalogue.push(new Produit(3, "ref 3","uniter centrale", 620));
catalogue.push(new Produit(4, "ref 4","ecran", 120));
var panier= new Array();
function remplirCatalogue() {
var cat= document.getElementById('cat');
for (var i in catalogue) {
var e= document.createElement("p");
e.value=i;
var txt= document.createTextNode(catalogue[i].id + " " + catalogue[i].reference + " " + catalogue[i].designation + " " + catalogue[i].prix);
var txt2=document.createElement("input");
e.appendChild(txt);
e.appendChild(txt2);
cat.appendChild(e);
}
}
function ajouterCase(parent, txt) {
var e= document.createElement("td");
e.appendChild(document.createTextNode(txt));
parent.appendChild(e);
}
function calculerTotal() {
var tot= 0;
for (var produit in panier) {
tot+= panier[produit].prix;
}
return tot;
}
function ajouter() {
/*var cat= document.getElementById('cat');
var sel= cat.options[cat.selectedIndex].value;*/
var cat= document.getElementById('cat');
var sel= inputProduit;
var prod= catalogue[sel];
panier.push(prod);
var ligne= document.createElement("tr");
ajouterCase(ligne,prod.reference);
ajouterCase(ligne,prod.designation);
ajouterCase(ligne,prod.prix);
document.getElementById("pan").appendChild(ligne);
document.getElementById("tot").innerHTML= calculerTotal();
}
remplirCatalogue();
const inputs = document.querySelectorAll(".ligne_article input");
inputs.forEach((NbrProduit) => {
NbrProduit.addEventListener("change", (e) => {
alert(NbrProduit.value);
CalculPanier(NbrProduit.value);
});
});
</script>
<div id="cat" class="ligne_article"></div>
<div class="reduction_impot"><span id="totaldon"></span> Total Panier</div>
<table id="pan">
<tr><th>référence</th><th>designation</th><th>prix</th></tr>
</table>
<p>Total <span id="tot">0</span></p> |
Partager