Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript
JavaScript Forum programmation JavaScript. Lire : Cours JavaScript, FAQ JavaScript, Toutes les FAQ JavaScript et Sources JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 21/12/2011, 11h10   #1
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
Par défaut faire la somme d'une colonne

Bonjour,

J'ai un souci a faire la somme d'une colonne de x nombre de ligne...Voici le code de mon formulaire:
Code :
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
<script language="javascript">
var index = 0;
function loadData(valeur, indexLine) {
	var data ;
	var url = "ajax.php?reference=" + valeur;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else return(false);
	xhr_object.open("GET", url, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) {
		//alert(xhr_object.responseText);
		data = eval(xhr_object.responseText);
		document.getElementById("designation[" + indexLine + "]").value = data[1];
		val_tarif=document.getElementById("tarif[" + indexLine + "]").value = data[2];
		document.getElementById("colis[" + indexLine + "]").value = data[3];	
		document.getElementById("punet[" + indexLine + "]").value = data[2];
		document.getElementById("total[" + indexLine + "]").value = data[2];
	document.getElementById("montant_total").value = data[2];		
	} else return(false);
}
function calcul_remise(value,indexLine){
	var val_tarif=document.getElementById("tarif[" + indexLine + "]").value
	var val_remise = document.getElementById("remise[" + indexLine + "]").value;
	val_punet = val_tarif - (val_tarif*val_remise*1/100);
document.getElementById("punet[" + indexLine + "]").value = val_punet;
var quantite = document.getElementById("quantite[" + indexLine + "]").value;
 
var prix_total = quantite * val_punet;
document.getElementById("total[" + indexLine + "]").value = prix_total;
document.getElementById("montant_total").value = prix_total;	
 
//alert(val_tarif);
	}
	function calcul_quantite(value,indexLine){
	var val_punet=document.getElementById("punet[" + indexLine + "]").value
var quantite = document.getElementById("quantite[" + indexLine + "]").value;
 
var prix_total = quantite * val_punet;
document.getElementById("total[" + indexLine + "]").value = prix_total;
//alert(val_tarif);
 
	}
function addLine() {
	var newRow = document.getElementById('matable').insertRow(-1);
	var reference = newRow.insertCell(0);
	reference.innerHTML = '<input type="text" id="reference['+ index + ']" name="reference['+ index + ']" onChange="loadData(this.value, '+ index +')" />';
	var designation = newRow.insertCell(1);
	designation.innerHTML = '<input type="text" id="designation['+ index + ']"  name="designation['+ index + ']" readonly />';
	var quantite = newRow.insertCell(2);
	quantite.innerHTML = '<input type="text" id="quantite['+ index + ']" name="quantite['+ index + ']" value="1" onChange="calcul_quantite(this.value, '+ index +')" OnKeyUp = "somme()" />';
	var colis = newRow.insertCell(3);
	colis.innerHTML = '<input type="text" id="colis['+ index + ']" name="colis['+ index + ']" value="" />';
	var remise = newRow.insertCell(4);
	remise.innerHTML = '<input type="text" id="remise['+ index + ']" name="remise['+ index + ']" value="" onChange="calcul_remise(this.value, '+ index +')" />';
	var tarif = newRow.insertCell(5);
	tarif.innerHTML = '<input type="text" id="tarif['+ index + ']" name="tarif['+ index + ']" value="" readonly  />';
	var punet = newRow.insertCell(6);
	punet.innerHTML = '<input type="text" id="punet['+ index + ']" name="punet['+ index + ']" value="" />';
	var total = newRow.insertCell(7);
	total.innerHTML = '<input type="text" id="total['+ index + ']" name="total['+ index + ']" value="" />';
	index++;
}
function deleteLine() {
	var nb = document.getElementById('matable').rows.length;
document.getElementById('matable').deleteRow(-1);
}
function somme(){
	var n = index;
	//alert(n);
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					parseInt(document.getElementById("montant_total").value)+
					parseInt(document.getElementById("total[" + n + "]").value);
			n++;
		}
}
</script>
</head>
 
<body>
 
<form method="post" action="commande.php">
<table id="matable" width="1048" border="0">
 
  <tr>
    <td width="111"><strong>REFERENCE</strong></td>
    <td width="131"><strong>DESIGNATION</strong></td>
    <td width="66"><strong>Quantité</strong></td>
    <td width="94"><strong>COLIS</strong></td>
    <td width="138"><strong>Remise(%)</strong></td>
    <td width="157"><strong>TARIF(FCFA)</strong></td>
    <td width="143"><strong>PU NET (FCFA)</strong></td>
    <td width="174"><strong>TOTAL (FCFA)</strong></td>
  </tr>
 
</table>
<table width="1367" id="matable2">
  <tr>
    <td width="87"></td>
    <td width="103"></td>
    <td width="51"></td>
    <td width="73"></td>
    <td width="108"></td>
    <td width="124"></td>
    <td width="157"></td>
     <td width="291"></td>
    <td width="333"><strong>Montant Total:</strong><input type="text" id="montant_total" name="montont_total" value="" /></td>
  </tr>
</table>
<input type="button" name="button" id="button" value="Ajouter" onClick="addLine()" />
<input type="button" name="button3" id="button3" value="Supprimer" onClick="deleteLine()" />
<input type="submit" name="button2" id="button2" value="Valider" />
 
</form>
</body>
</html>
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h43   #2
Membre Expert
 
Avatar de rotrevrep
 
Homme yannick inizan
Secrétaire d'état à la procrastination
Inscription : février 2011
Messages : 304
Détails du profil
Informations personnelles :
Nom : Homme yannick inizan
Âge : 25
Localisation : France, Cher (Centre)

Informations professionnelles :
Activité : Secrétaire d'état à la procrastination
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2011
Messages : 304
Points : 1 118
Points : 1 118
Envoyer un message via MSN à rotrevrep Envoyer un message via Skype™ à rotrevrep
dis moi si je me trompe, mais je ne vois qu'un id total[n], donc ta somme aura toujours la même valeur
__________________
(marquer un post résolu si vous êtes satisfait de la réponse )
le chat caramail de retour ? :/ http://www.tchats.net/beta.php
les projets web en cours sont sur : https://github.com/rotrevrep
rotrevrep est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 12h02   #3
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
L'id total[n] est la somme de chaque ligne et l'id montant_total est la somme total des total[n].je veux que a chaque fois qu'on change la quantité ou la remise que le montant_total change en fonction aussi
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 12h50   #4
Membre Expert
 
Avatar de rotrevrep
 
Homme yannick inizan
Secrétaire d'état à la procrastination
Inscription : février 2011
Messages : 304
Détails du profil
Informations personnelles :
Nom : Homme yannick inizan
Âge : 25
Localisation : France, Cher (Centre)

Informations professionnelles :
Activité : Secrétaire d'état à la procrastination
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2011
Messages : 304
Points : 1 118
Points : 1 118
Envoyer un message via MSN à rotrevrep Envoyer un message via Skype™ à rotrevrep
en fait, modifie ta fonction somme :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
function somme(){
	var n = 0;
document.getElementById("montant_total").value = 0;
	//alert(n);
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					parseInt(document.getElementById("montant_total").value)+
					parseInt(document.getElementById("total[" + n + "]").value);
			n++;
		}
}
ceci devrait fonctionner
__________________
(marquer un post résolu si vous êtes satisfait de la réponse )
le chat caramail de retour ? :/ http://www.tchats.net/beta.php
les projets web en cours sont sur : https://github.com/rotrevrep
rotrevrep est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 13h16   #5
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
Probléme résolu voici le code pour ceux qui aurant le méme probléme:

Code :
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
<script language="javascript">
var index = 0;
function loadData(valeur, indexLine) {
	var data ;
	var url = "ajax.php?reference=" + valeur;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else return(false);
	xhr_object.open("GET", url, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) {
		//alert(xhr_object.responseText);
		data = eval(xhr_object.responseText);
		document.getElementById("designation[" + indexLine + "]").value = data[1];
		val_tarif=document.getElementById("tarif[" + indexLine + "]").value = data[2];
		document.getElementById("colis[" + indexLine + "]").value = data[3];	
		document.getElementById("punet[" + indexLine + "]").value = data[2];
		document.getElementById("total[" + indexLine + "]").value = data[2];
	var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					parseInt(document.getElementById("montant_total").value)+
					parseInt(document.getElementById("total[" + n + "]").value);
			n++;
		}	
 
	} else return(false);
}
function calcul_remise(value,indexLine){
	var val_tarif=document.getElementById("tarif[" + indexLine + "]").value
	var val_remise = document.getElementById("remise[" + indexLine + "]").value;
	val_punet = val_tarif - (val_tarif*val_remise*1/100);
document.getElementById("punet[" + indexLine + "]").value = val_punet;
var quantite = document.getElementById("quantite[" + indexLine + "]").value;
 
var prix_total = quantite * val_punet;
document.getElementById("total[" + indexLine + "]").value = prix_total;
document.getElementById("montant_total").value = prix_total;	
 
//alert(val_tarif);
	}
	function calcul_quantite(value,indexLine){
	var val_punet=document.getElementById("punet[" + indexLine + "]").value
var quantite = document.getElementById("quantite[" + indexLine + "]").value;
 
var prix_total = quantite * val_punet;
document.getElementById("total[" + indexLine + "]").value = prix_total;
//alert(val_tarif);
	var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					parseInt(document.getElementById("montant_total").value)+
					parseInt(document.getElementById("total[" + n + "]").value);
			n++;
		}
	}
function addLine() {
	var newRow = document.getElementById('matable').insertRow(-1);
	var reference = newRow.insertCell(0);
	reference.innerHTML = '<input type="text" id="reference['+ index + ']" name="reference['+ index + ']" onChange="loadData(this.value, '+ index +')" />';
	var designation = newRow.insertCell(1);
	designation.innerHTML = '<input type="text" id="designation['+ index + ']"  name="designation['+ index + ']" readonly />';
	var quantite = newRow.insertCell(2);
	quantite.innerHTML = '<input type="text" id="quantite['+ index + ']" name="quantite['+ index + ']" value="1" onChange="calcul_quantite(this.value, '+ index +')"  />';
	var colis = newRow.insertCell(3);
	colis.innerHTML = '<input type="text" id="colis['+ index + ']" name="colis['+ index + ']" value="" />';
	var remise = newRow.insertCell(4);
	remise.innerHTML = '<input type="text" id="remise['+ index + ']" name="remise['+ index + ']" value="" onChange="calcul_remise(this.value, '+ index +')" />';
	var tarif = newRow.insertCell(5);
	tarif.innerHTML = '<input type="text" id="tarif['+ index + ']" name="tarif['+ index + ']" value="" readonly  />';
	var punet = newRow.insertCell(6);
	punet.innerHTML = '<input type="text" id="punet['+ index + ']" name="punet['+ index + ']" value="" />';
	var total = newRow.insertCell(7);
	total.innerHTML = '<input type="text" id="total['+ index + ']" name="total['+ index + ']" value="" />';
	index++;
}
function deleteLine() {
	var nb = document.getElementById('matable').rows.length;
document.getElementById('matable').deleteRow(-1);
}
/*function somme(){
	var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					parseInt(document.getElementById("montant_total").value)+
					parseInt(document.getElementById("total[" + n + "]").value);
			n++;
		}
}*/
</script>
</head>
 
<body>
 
<form method="post" action="commande.php">
<table id="matable" width="1048" border="0">
 
  <tr>
    <td width="111"><strong>REFERENCE</strong></td>
    <td width="131"><strong>DESIGNATION</strong></td>
    <td width="66"><strong>Quantité</strong></td>
    <td width="94"><strong>COLIS</strong></td>
    <td width="138"><strong>Remise(%)</strong></td>
    <td width="157"><strong>TARIF(FCFA)</strong></td>
    <td width="143"><strong>PU NET (FCFA)</strong></td>
    <td width="174"><strong>TOTAL (FCFA)</strong></td>
  </tr>
 
</table>
<table width="1367" id="matable2">
  <tr>
    <td width="87"></td>
    <td width="103"></td>
    <td width="51"></td>
    <td width="73"></td>
    <td width="108"></td>
    <td width="124"></td>
    <td width="157"></td>
     <td width="291"></td>
    <td width="333"><strong>Montant Total:</strong><input type="text" id="montant_total" name="montont_total" value="" /></td>
  </tr>
</table>
<input type="button" name="button" id="button" value="Ajouter" onClick="addLine()" />
<input type="button" name="button3" id="button3" value="Supprimer" onClick="deleteLine()" />
<input type="submit" name="button2" id="button2" value="Valider" />
 
</form>
</body>
</html>
 
</html>
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 13h16   #6
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
merci à rotrevrep!!!
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/12/2011, 15h58   #7
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
voila je suis entrain de faire un script qui ajoute et supprime une ligne d'un tableau contenant des champs input et fait le total d'une colonne tout marche sauf que quand je supprime une ligne et en rajoute une autre il ne voit pas la derniére ligne ajoutée. voici mon script
Code :
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="media/style.css">
<title>Document sans titre</title>
<script language="javascript">
var index = 1;
function loadData(valeur, indexLine) {
	var data ;
	var url = "ajax.php?reference=" + valeur;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else return(false);
	xhr_object.open("GET", url, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) {
		//alert(xhr_object.responseText);
		data = eval(xhr_object.responseText);
		document.getElementById("designation[" + indexLine + "]").value = data[1];
		val_tarif=document.getElementById("tarif[" + indexLine + "]").value = data[2];
		document.getElementById("colis[" + indexLine + "]").value = data[3];	
		document.getElementById("punet[" + indexLine + "]").value = data[2];
		document.getElementById("total[" + indexLine + "]").value = data[2];
	var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					(parseFloat(document.getElementById("montant_total").value)+
					parseFloat(document.getElementById("total[" + n + "]").value)).toFixed(2);
			n++;
		}	
 
	} else return(false);
}
function calcul_remise(value,indexLine){
	var val_tarif=document.getElementById("tarif[" + indexLine + "]").value
	var val_remise = document.getElementById("remise[" + indexLine + "]").value;
	val_punet = val_tarif - (val_tarif*val_remise*1/100);
document.getElementById("punet[" + indexLine + "]").value = val_punet;
var quantite = document.getElementById("quantite[" + indexLine + "]").value;
 
var prix_total = quantite * val_punet;
document.getElementById("total[" + indexLine + "]").value = prix_total;
var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					(parseFloat(document.getElementById("montant_total").value)+
					parseFloat(document.getElementById("total[" + n + "]").value)).toFixed(2);
			n++;
		}
 
//alert(val_tarif);
	}
	function calcul_quantite(value,indexLine){
	var val_punet=document.getElementById("punet[" + indexLine + "]").value
var quantite = document.getElementById("quantite[" + indexLine + "]").value;
 
var prix_total = quantite * val_punet;
document.getElementById("total[" + indexLine + "]").value = prix_total;
//alert(val_tarif);
	var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					(parseFloat(document.getElementById("montant_total").value)+
					parseFloat(document.getElementById("total[" + n + "]").value)).toFixed(2);
			n++;
		}
	}
function addLine() {
	var newRow = document.getElementById('matable').insertRow(-1);
	var reference = newRow.insertCell(0);
	reference.innerHTML = '<input type="text" id="reference['+ index + ']" name="reference['+ index + ']" onChange="loadData(this.value, '+ index +')" />';
	var designation = newRow.insertCell(1);
	designation.innerHTML = '<input type="text" id="designation['+ index + ']"  name="designation['+ index + ']" readonly />';
	var quantite = newRow.insertCell(2);
	quantite.innerHTML = '<input type="text" id="quantite['+ index + ']" name="quantite['+ index + ']" value="1" onChange="calcul_quantite(this.value, '+ index +')"  />';
	var colis = newRow.insertCell(3);
	colis.innerHTML = '<input type="text" id="colis['+ index + ']" name="colis['+ index + ']" value="" />';
	var remise = newRow.insertCell(4);
	remise.innerHTML = '<input type="text" id="remise['+ index + ']" name="remise['+ index + ']" value="" onChange="calcul_remise(this.value, '+ index +')" />';
	var tarif = newRow.insertCell(5);
	tarif.innerHTML = '<input type="text" id="tarif['+ index + ']" name="tarif['+ index + ']" value="" readonly  />';
	var punet = newRow.insertCell(6);
	punet.innerHTML = '<input type="text" id="punet['+ index + ']" name="punet['+ index + ']" value="" />';
	var total = newRow.insertCell(7);
	total.innerHTML = '<input type="text" id="total['+ index + ']" name="total['+ index + ']" value="" />';
	index++;
}
function deleteLine() {
 
	var nb = document.getElementById('matable').rows.length;
	if(nb > 2){
		//alert(nb);
document.getElementById('matable').deleteRow(-1);
	}
var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					(parseFloat(document.getElementById("montant_total").value)+
					parseFloat(document.getElementById("total[" + n + "]").value)).toFixed(2);
			n++;
		}
 
	alert(n);
 
}
/*function somme(){
	var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					parseInt(document.getElementById("montant_total").value)+
					parseInt(document.getElementById("total[" + n + "]").value);
			n++;
		}
}*/
</script>
</head>
 
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form method="post" action="commande.php">
 
<table id="matable" width="1048" border="0">
 
  <tr>
    <td width="111"><strong>REFERENCE</strong></td>
    <td width="131"><strong>DESIGNATION</strong></td>
    <td width="66"><strong>Quantité</strong></td>
    <td width="94"><strong>COLIS</strong></td>
    <td width="138"><strong>Remise(%)</strong></td>
    <td width="157"><strong>TARIF(FCFA)</strong></td>
    <td width="143"><strong>PU NET (FCFA)</strong></td>
    <td width="174"><strong>TOTAL (FCFA)</strong></td>
  </tr>
   <tr>
    <td width="111"><input type="text" id="reference[0]" name="reference[0]" onChange="loadData(this.value, 0)" /></td>
    <td width="131"><input type="text" id="designation[0]"  name="designation[0]" readonly /></td>
    <td width="66"><input type="text" id="quantite[0]" name="quantite[0]" value="1" onChange="calcul_quantite(this.value, 0)"  /></td>
    <td width="94"><input type="text" id="colis[0]" name="colis[0]" value="" /></td>
    <td width="138"><input type="text" id="remise[0]" name="remise[0]" value="" onChange="calcul_remise(this.value, 0)" /></td>
    <td width="157"><input type="text" id="tarif[0]" name="tarif[0]" value="" readonly  /></td>
    <td width="143"><input type="text" id="punet[0]" name="punet[0]" value="" /></td>
    <td width="174"><input type="text" id="total[0]" name="total[0]" value="" /></td>
  </tr>
 
</table>
<table width="1367" id="matable2">
  <tr>
    <td width="87"></td>
    <td width="103"></td>
    <td width="51"></td>
    <td width="73"></td>
    <td width="108"></td>
    <td width="124"></td>
    <td width="157"></td>
     <td width="291"></td>
    <td width="333"><strong>Montant Total:</strong><input type="text" id="montant_total" name="montont_total" value="" /></td>
  </tr>
</table>
<input type="button" name="button" id="button" value="Ajouter" onClick="addLine()" />
<input type="button" name="button3" id="button3" value="Supprimer" onClick="deleteLine()" />
<input type="submit" name="button2" id="button2" value="Valider" />
 
</form>
</body>
</html>
 
</html>
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/12/2011, 17h04   #8
Membre Expert
 
Avatar de rotrevrep
 
Homme yannick inizan
Secrétaire d'état à la procrastination
Inscription : février 2011
Messages : 304
Détails du profil
Informations personnelles :
Nom : Homme yannick inizan
Âge : 25
Localisation : France, Cher (Centre)

Informations professionnelles :
Activité : Secrétaire d'état à la procrastination
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2011
Messages : 304
Points : 1 118
Points : 1 118
Envoyer un message via MSN à rotrevrep Envoyer un message via Skype™ à rotrevrep
pourrait tu rajouter ton ficher ajax.php ?
Edit : en fait, je viens de tester ton script, et il fonctionne correctement, il met bien à jour le total à l'ajout ou à la suppression. Si il y a un autre problème, dis le.
__________________
(marquer un post résolu si vous êtes satisfait de la réponse )
le chat caramail de retour ? :/ http://www.tchats.net/beta.php
les projets web en cours sont sur : https://github.com/rotrevrep
rotrevrep est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/12/2011, 17h16   #9
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
au fait le probléme vient de la fonction deleteLine() physiquement il ne supprime, pas la ligne parce quand je refait un ajout le nombre de ligne ne s'incrémente.
Par exemple si j'ai 4 lignes je supprime il devrait me rester 3 ligne mais quand je refaits un ajout au lieu d'avoir 4 j'ai 3.
j'ai fait un alert sur la fonction loadData() et deleteline() comme suit
Code :
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
 
/***fonction loaData****/
function loadData(valeur, indexLine) {
	var data ;
	var url = "ajax.php?reference=" + valeur;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else return(false);
	xhr_object.open("GET", url, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) {
		//alert(xhr_object.responseText);
		data = eval(xhr_object.responseText);
		document.getElementById("designation[" + indexLine + "]").value = data[1];
		val_tarif=document.getElementById("tarif[" + indexLine + "]").value = data[2];
		document.getElementById("colis[" + indexLine + "]").value = data[3];	
		document.getElementById("punet[" + indexLine + "]").value = data[2];
		document.getElementById("total[" + indexLine + "]").value = data[2];
	var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					(parseFloat(document.getElementById("montant_total").value)+
					parseFloat(document.getElementById("total[" + n + "]").value)).toFixed(2);
			n++;
		}
		alert(n);	
 
	} else return(false);
}
/***supprime ligne****/
function deleteLine() {
 
	var nb = document.getElementById('matable').rows.length;
	if(nb > 2){
		//alert(nb);
document.getElementById('matable').deleteRow(-1);
	}
var n = 0;
	//alert(n);
	document.getElementById("montant_total").value = 0;
while ( document.getElementById("total[" + n + "]") )
		{	
		//alert(document.getElementById("total[" + n + "]"));
		document.getElementById("montant_total").value=
					(parseFloat(document.getElementById("montant_total").value)+
					parseFloat(document.getElementById("total[" + n + "]").value)).toFixed(2);
			n++;
		}
 
	alert(n);
 
}
voici mon fichier ajax.php
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
<?php
$reference = $_GET["reference"];
 
 
include "connexion/connexion.php";
 
$bd_connexion = mysql_select_db($database_connexion);
$insertSQL = sprintf("select code_article,designation,colisage,prix_unitaire from articles where code_article='$reference';");
$query = mysql_query($insertSQL,$connexion) or die(mysql_error());
 
$row = mysql_fetch_row($query);
echo "new Array('".$row[0]."', '".$row[1]."', '".$row[3]."','".$row[2]."')";
?>
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/12/2011, 17h18   #10
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
as-tu essayé de supprimer et de rajouter?
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/12/2011, 18h41   #11
Modérateur
 
Avatar de NoSmoking
 
Homme
Inscription : janvier 2011
Messages : 2 944
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Isère (Rhône Alpes)

Informations forums :
Inscription : janvier 2011
Messages : 2 944
Points : 4 776
Points : 4 776
Bonjour,
juste un truc qui surprend, tu incrémentes un compteur, index, lors des ajouts mais tu ne décrémentes pas celui ci lors des suppressions .
NoSmoking est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 03/01/2012, 10h43   #12
Nouveau Membre du Club
 
Inscription : juin 2005
Messages : 140
Détails du profil
Informations forums :
Inscription : juin 2005
Messages : 140
Points : 28
Points : 28
Envoyer un message via MSN à jules_diedhiou Envoyer un message via Yahoo à jules_diedhiou
merci tu as parfaitement raison et ça régle mon probléme

grand merci
jules_diedhiou est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h36.


 
 
 
 
Partenaires

Hébergement Web