bonsoir à tous,


j'ai une page web ou il y a du javascript pour la création d'un taleau html. il fonctionne mais je voudrait arrivé a supprimer la dernier ligne de mon tableau.

En fait je remplis les case input, je clique sur ajouter et cela créer un tableau html.

Mais je voudrais qu'au depart il supprime la derniere ligne ( cette ligne est créé plus bas pour faire la somme du colonne.)

J'ai essayé ceci:

Code : 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
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
 
 
ar EMB =
 
    {
 
        nbEmballage : 0,
 
        idEmballage : 0,
 
        ajouter : function ()
 
        {
 
		if (EMB.nbEmballage == 0)
            {
            }
		else
		{
		var tbody = document.getElementById('liste-emballage');
		row = document.getElementById("ajout").rows.length;
		alert(row);
		document.getElementById('ajout').deleteRow(row);
		}
		            var e = document.getElementById('emballage');
            var qe = document.getElementById('qte_emb');
			var pu = document.getElementById('pu_emb');
			var total = document.getElementById('pu_emb').value.replace(/(,)/gi, ".") * document.getElementById('qte_emb').value.replace(/(,)/gi, ".");
            var tbody = document.getElementById('liste-emballage');
            if (EMB.nbEmballage == 0) { tbody.deleteRow(0); }
            var tr = tbody.insertRow(tbody.rows.length);
            var td1 = tr.insertCell(0);
            var td2 = tr.insertCell(1);
            var td3 = tr.insertCell(2);
			var td4 = tr.insertCell(3);
			var td5 = tr.insertCell(4);
 
            // Insertion produit
 
            var emb = document.createTextNode(e.options[e.selectedIndex].text);
            var embInput = document.createElement('input');
            embInput.setAttribute('type', 'hidden');
            embInput.setAttribute('name', 'emballage[' + EMB.idEmballage + '][0]');
            embInput.setAttribute('value', e.options[e.selectedIndex].value);
            td1.appendChild(emb);
            td1.appendChild(embInput);
 
            // Insertion quantité
 
            var embqtte = document.createTextNode(qe.value);
            var embqtteInput = document.createElement('input');
            embqtteInput.setAttribute('type', 'hidden');
            embqtteInput.setAttribute('name', 'qte[' + EMB.idEmballage + '][1]');
            embqtteInput.setAttribute('value', qe.value.replace(/(,)/gi, "."));
            td2.appendChild(embqtte);
            td2.appendChild(embqtteInput);
 
                        // Insertion prix
 
            var embprix = document.createTextNode(pu.value);
            var embprixInput = document.createElement('input');
            embprixInput.setAttribute('type', 'hidden');
            embprixInput.setAttribute('name', 'pu[' + EMB.idEmballage + '][2]');
            embprixInput.setAttribute('value', pu.value.replace(/(,)/gi, "."));
            td3.appendChild(embprix);
            td3.appendChild(embprixInput);
 
			// Bouton supprimer
 
            var btnSupprimer = document.createElement('input');
            btnSupprimer.setAttribute('type', 'button');
            btnSupprimer.setAttribute('value', 'Supprimer');
            btnSupprimer.onclick = EMB.supprimer;
            td4.appendChild(btnSupprimer);
 
			// Total par produit:
			//alert ('test'+total);
			//var embtotal = document.getElementById('pu_emb').value.replace(/(,)/gi, ".") * document.getElementById('qte_emb').value.replace(/(,)/gi, ".");
            var embtotal = document.createTextNode(total);
			var embtotalInput = document.createElement('input');
            embtotalInput.setAttribute('type', 'hidden');
            embtotalInput.setAttribute('name', 'total[' + EMB.idEmballage + '][3]');
            embtotalInput.setAttribute('value', total);
 
			td5.appendChild(embtotal);
            td5.appendChild(embtotalInput);
 
 
			//Calcul Complet total
			var tr =  tbody.insertRow(tbody.rows.length);
			var td1 = tr.insertCell(0);
			var td2 = tr.insertCell(1);
			var total = document.createTextNode('test');
			td1.setAttribute('colSpan', 4);
			td1.appendChild(total);
			//var montanttotal = 0;
			//var nbLignes3 = document.getElementById("ajout").rows.length - 2;
			//for (a=1;a<=nbLignes3;a++)
			//{
			//montanttotal = montanttotal + parseFloat(document.getElementById('total[' + a + '][3]').value);
           // }
			//alert ('montanttotal'+motanttotal);
			//var total = document.createTextNode(totaltotal);
			//var totalInput = document.createElement('input');
           // totalInput.setAttribute('type', 'hidden');
           // totalInput.setAttribute('name', 'total');
           // totalInput.setAttribute('value', total);
 
			//td2.appendChild(total);
            //td2.appendChild(totalInput);	
 
 
 
			// Inc nbProduits et id
            EMB.nbEmballage++;
            EMB.idEmballage++;
 
        },
 
        supprimer : function ()
 
        {
 
            var tbody = document.getElementById('liste-emballage');
            var row = this.parentNode.parentNode;
            var index = 0;
            while (row = row.previousSibling)
            {
                if (row.tagName) { index++; }
            }
 
            tbody.deleteRow(index);
            EMB.nbEmballage--;
            if (EMB.nbEmballage == 0)
            {
                var tr = tbody.insertRow(0);
                var td = tr.insertCell(0);
                td.setAttribute('colSpan', 5);
                td.appendChild(document.createTextNode('Aucun emballage'));
            }
        },
 
        check : function ()
        {
            if (EMB.nbEmballage < 1) alert('Il faut au moins 1 emballage');
            return EMB.nbEmballage > 0;
        }
    };
uncaught exception: Index or size is negative or greater than the allowed amount (NS_ERROR_DOM_INDEX_SIZE_ERR)
[Break on this error] document.getElementById('ajout').deleteRow(row);


Ou Est je commis une erreur?
le code erreur est celui ci (c'est celui qui doit faire la suppression de la dernière ligne):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
var tbody = document.getElementById('liste-emballage');
      row = document.getElementById("ajout").rows.length;
      alert(row);
      document.getElementById('ajout').deleteRow(row);
      }
Merci

guigui69