JavaScript - Formulario de pedido que recalcule el total

 
Vista:
sin imagen de perfil

Formulario de pedido que recalcule el total

Publicado por carmen (2 intervenciones) el 01/09/2014 11:48:52
Buenos días!
Estoy haciendo un formulario de pedido que según la cantidad introducida de artículos, muestre el precio total.
El problema está en que al modificar la cantidad de uno de los artículos, el precio total se va acumulandp, y no recalculando. No sé qué función agregar para que esto no ocurra, sería cuestión de introducir un "subtotal", pero no consigo hacerlo. También tengo una celda para calcular un descuento del 5% del total y restarlo al precio. No funciona bien, y no sé tampoco qué sucede.
Alguien me podía dar una pista?
Os dejo código-
:
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<title></title>
 
<script>
 
function validarNumero(e) {
 
           tecla = e.which || e.keyCode;
 
           patron = /\d/; // Solo acepta números
 
           te = String.fromCharCode(tecla);
 
           return (patron.test(te) || tecla == 9 || tecla == 8);
 
         }
 
 
 function validateEmail(theElement, nombre_del_elemento )
{
var evaluar = theElement.value;
var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (evaluar.length == 0 ) return true;
if (filter.test(evaluar))
return true;
else
alert("Inkorrekte Email");
theElement.focus();
return false;
}
 
 
function calculo(cantidad,precio,inputtext,totaltext){
 
	/* Parametros:
	cantidad - entero con la cantidad
	precio - entero con el precio
	inputtotal - nombre del elemento del formulario donde ira el total
	*/
 
	// Calculo del subtotal
	subtotal = precio*cantidad;
	inputtext.value=subtotal;
 
	//Actualizar el total
	// Utilizamos el eval. Ya que el valor es un texto y si lo tratamos como tal
	// es como si estuviesemos manipulando una cadena.
	total = eval(totaltext.value);
	totaltext.value = total + subtotal;
 
	rabattfield = document.getElementById("rabatt");
	totwithrab = document.getElementById("totalwithrabatt");
 
	rabattfield.value = total*5/100;
	totwithrab.value = total*95/100;
 
 
	}
 
function multiplicar(){
r = 0.05;
total = document.getElementById("total").value;
rabatt = r*total;
document.getElementById("rabatt").value = rabatt;
}
 
function justNumbers(e, field)
{
var keynum = window.event ? window.event.keyCode : e.which;
if ((keynum == 8) || (keynum == 46)) {
	return true;
}
return /\d/.test(String.fromCharCode(keynum));
}
 
    function foo() {
        		return confirm("Möchten Sie die Bestellung senden?");
 
    }
 
 
</script>
 
</head>
<link rel="stylesheet" type="text/css" href="jquery-ui-1.9.2.custom.min.css">
 
<script type='text/javascript' src="PRUEBAjquery-1.7.1.min.js"></script>
 
<style type="text/css">
body {
	font-family: Arial;
	background-color: #dfcfa8;
	font-size: 14px;
}
.background{
 
	position: absolute; /*nos posicionamos en el centro del navegador*/
	top:50%; left:50%; /*determinamos una anchura*/
	width:1100px; /*indicamos que el margen izquierdo, es la mitad de la anchura*/
	margin-left:-550px; /*determinamos una altura*/
	height:677px; /*indicamos que el margen superior, es la mitad de la altura*/
	margin-top:-338px;
 
}
.background.span {
    position: absolute;
   	left: 0;
}
#contenedortabla{
position:absolute;
top:110px ; /*mover esto para alinearlo verticalmente*/
left:220px; /*mover esto para alinearlo a la horizontalmente*/
}
 
#boton2 {
	position: absolute;
	top: 10px;
	left: 10px;
}
 
 
.pagemargins{padding-left:40px;padding-right:40px;}.footermargins{padding-left:40px;padding-right:40px;}#form{width:501px;}#pagecountspan{display:none;}#p1f1{width:421px;}#p1f1 .fieldlabel{padding-top:3px;}#p1f2{width:421px;}#p1f2 .caption{width:116px;}#p1f2 .control{width:291px;}#p1f2 .fieldlabel{padding-top:3px;}#p1f2c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:283px;max-width:283px;}#p1f3{width:421px;}#p1f3 .caption{width:116px;}#p1f3 .control{width:291px;}#p1f3 .fieldlabel{padding-top:3px;}#p1f3c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:283px;max-width:283px;}#p1f4{width:160px;}#p1f4 .caption{width:116px;}#p1f4 .control{
	width: 50px;
}#p1f4 .fieldlabel{padding-top:3px;}#p1f4c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:50px;max-width:50px;}#p1f5{width:231px;}#p1f5 .caption{width:20px;}#p1f5 .control{width:197px;}#p1f5 .fieldlabel{padding-top:3px;}#p1f5c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:189px;max-width:189px;}#p1f6{width:421px;}#p1f6 .caption{width:116px;}#p1f6 .control{width:291px;}#p1f6 .fieldlabel{padding-top:3px;}#p1f6c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:283px;max-width:283px;}#p1f7{width:421px;}#p1f7 .caption{width:116px;}#p1f7 .control{width:291px;}#p1f7 .fieldlabel{padding-top:3px;}#p1f7c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:283px;max-width:283px;}#p1f8{width:500px;}#p1f8 .fieldlabel{padding-top:3px;}#p1f9{width:421px;}#p1f9 .caption{width:116px;}#p1f9 .control{width:291px;}#p1f9 .fieldlabel{padding-top:3px;}#p1f9c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:283px;max-width:283px;}#p1f10{width:421px;}#p1f10 .caption{width:116px;}#p1f10 .control{width:291px;}#p1f10 .fieldlabel{padding-top:3px;}#p1f10c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:283px;max-width:283px;}#p1f11{width:161px;}#p1f11 .caption{width:116px;}#p1f11 .control{width:31px;}#p1f11 .fieldlabel{padding-top:3px;}#p1f11c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:50px;max-width:50px;}#p1f12{width:230px;}#p1f12 .caption{width:21px;}#p1f12 .control{width:195px;}#p1f12 .fieldlabel{padding-top:3px;}#p1f12c{font-family:Arial, Helvetica, sans-serif;font-size:14px;width:187px;max-width:187px;}#p1f13{width:440px;}#p1f13 .fieldlabel{padding-top:3px;}#p1f13 .staticcontrol > div{border-style:double;border-color:#002865;}#p1f14{width:421px;}#p1f14 .fieldlabel{padding-top:3px;}#p1f15{width:69px;}#p1f15 .fieldlabel{padding-top:3px;}#p1f16{width:55px;}#p1f16 .fieldlabel{padding-top:3px;}#p1f17{width:89px;}#p1f17 .fieldlabel{padding-top:3px;}#p1f18{width:105px;}#p1f18 .fieldlabel{padding-top:3px;}#p1f19{width:121px;}#p1f19 .fieldlabel{padding-top:3px;}#p1f20{
	width: 90px;
}#p1f20 .fieldlabel{padding-top:3px;}#p1f21{width:129px;}#p1f21 .fieldlabel{padding-top:3px;}#p1f22{
	width: 80px;
}#p1f22 .fieldlabel{padding-top:3px;}#p1f23{width:40px;}#p1f23 .fieldlabel{padding-top:3px;}#p1f24{
	width: 90px;
}#p1f24 .fieldlabel{padding-top:3px;}#p1f25{width:40px;}#p1f25 .fieldlabel{padding-top:3px;}#p1f26{
	width: 80px;
}#p1f26 .fieldlabel{padding-top:3px;}#p1f27{
	width: 90px;
}#p1f27 .fieldlabel{padding-top:3px;}#p1f28{width:421px;}#p1f28 .fieldlabel{padding-top:3px;}#p1f29{
	width: 80px;
}#p1f29 .fieldlabel{padding-top:3px;}#p1f30{
	width: 90px;
}#p1f30 .fieldlabel{padding-top:3px;}#p1f31{width:421px;}#p1f31 .fieldlabel{padding-top:3px;}
 
.BOX {
	width: 90px;
}
 
.box {
	width: 90px;
}
.box {
	text-align: center;
}
p {
	font-weight:bold;
	color:#002865;
	font-style: italic;
}
h {
	font-size: 12px;
	color:red;
	font-style: italic;
 
</style>
</head>
<body>
 
<div class="background"> <img src="images/mann sin texto.jpg" width="1100px" height="677px" alt="" title="" />
  <div id="boton2">
  <a href="produkte.html" > <img src ="images/tierraprodukte.png" width="90px" height="80px" > </a>
</div>
 <span>
 
  <div id="contenedortabla">
 
 
 
 
  <div id="complete" class="formpage">
<div id="confirmmsg"></div>
 
 
</div>
 
 
<div style="height:460px;
scrollbar-base-color : #;
scrollbar-arrow-color : #; 
background-color:, overflow-y:visible;overflow-x:hidden;" >
 
<div id="page1" class="formpage" style="display:block;">
<div class="formrow f1">
<div id="p1f1" class="field textElement n1">
<div class="staticcontrol"><span class="wordwrap"><span class="pspan arial" style="font-size:18px;"><span class="ispan" style="font-weight:bold;color:#002865" xml:space="preserve">Rechnungsadresse</span></span></span></div>
<div class="null"></div>
</div>
<div class="null"></div>
</div>
<div class="formrow f1">
<div id="p1f2" class="field textField n1">
<div class="caption capleft alignleft">
<label class="fieldlabel" for="p1f2c"><span><span class="pspan arial" style="text-align:left;font-size:14px;"><span class="ispan" style="color:#002865" xml:space="preserve">Nam</div>
</div>
<div class="formrow f1">
<div id="p1f14" class="field textElement n1">
<p>
<div class="staticcontrol"><span class="wordwrap"><span class="pspan arial" style="font-size:18px;"><span class="ispan" style="font-weight:bold;color:#002865" xml:space="preserve">Bestellung</span></span></span></div>
<table width="500">
<tr>
  <td class="dcha"><table width="473">
    <tr height="10">
      <td width="465"><strong></strong></td>
    </tr>
  </table></td>
</tr>
</table>
</form>
 
</span>
 
</div>
 
</div>
  <span style="text-align:left">
  <input type="submit" value="Senden" onclick="return validateEmail(email,'email');return foo()"  />
  </span>
  <table width="440">
    <tr> </tr>
    <tr height="15">
      <td colspan="4"><div align="justify"><em>
        <h></h>
      </em></div></td>
    </tr>
    <tr height="5"></tr>
    <tr height="15">
      <td width="110"><strong>Artikel</strong></td>
      <td width="85" class="box1" align="center"><strong>Menge</strong></td>
      <td width="100" class="BOX1" align="center"><strong>Einzelpreis</strong></td>
      <td width="100" class="box1" align="center"><strong>Gesamtpreis</strong></td>
    </tr>
    <tr></tr>
    <tr>
      <td>Fix-Leintuch</td>
    </tr>
    <tr>
      <td class="dcha">200/90 cm</td>
      <td><input type="text" name="fl20090" onkeypress="return justNumbers(event, this)" size="3" id="20090" value="0" onchange="calculo(this.value,precio20090.value,total20090,total);" />
        Stk.</td>
      <td align="center"><input type="hidden" id="precio20090" value="309"/>
        309 CHF</td>
      <td align="center"><input type="text" size="6" id="total20090" value="0" disabled="true" />
        CHF</td>
    </tr>
    <tr>
      <td class="dcha">200/100 cm</td>
      <td><input type="text" name="fl200100" onkeypress="return justNumbers(event, this)" size="3" id="200/100" value="0" onchange="calculo(this.value,precio200100.value,total200100,total);" />
        Stk.</td>
      <td align="center" ><input type="hidden" id="precio200100" value="309"/>
        309 CHF</td>
      <td align="center"><input type="text" size="6" id="total200100" value="0"disabled="true" />
        CHF</td>
    </tr>
    <tr>
      <td class="dcha">200/140 cm</td>
      <td><input type="text" name="fl200140" onkeypress="return justNumbers(event, this)" size="3" id="200/140" value="0" onchange="calculo(this.value,precio200140.value,total200140,total);" />
        Stk.</td>
      <td align="center"><input type="hidden" id="precio200140" value="359"/>
        359 CHF</td>
      <td align="center"><input type="text" size="6" id="total200140" value="0" disabled="true" />
        CHF</td>
    </tr>
    <tr>
      <td class="dcha">200/160 cm</td>
      <td><input type="text" name="fl200160" onkeypress="return justNumbers(event, this)" size="3" id="200/160" value="0" onchange="calculo(this.value,precio200160.value,total200160,total);" />
        Stk.</td>
      <td align="center"><input type="hidden" id="precio200160" value="379"/>
        379 CHF</td>
      <td align="center"><input type="text" size="6" id="total200160" value="0" disabled="true" />
        CHF</td>
    </tr>
    <tr>
      <td class="dcha">200/180 cm</td>
      <td><input type="text" name="fl200180" onkeypress="return justNumbers(event, this)" size="3" id="200/180" value="0" onchange="calculo(this.value,precio200180.value,total200180,total);" />
        Stk.</td>
      <td align="center"><input type="hidden" id="precio200180" value="399"/>
        399 CHF</td>
      <td align="center"><input type="text" size="6" id="total200180" value="0" disabled="true" />
        CHF</td>
    </tr>
    <tr>
      <td class="dcha">200/200 cm</td>
      <td><input type="text" name="fl200200" onkeypress="return justNumbers(event, this)" size="3" id="200/200" value="0" onchange="calculo(this.value,precio200200.value,total200200,total);" />
        Stk.</td>
      <td align="center"><input type="hidden" id="precio200200" value="419"/>
        419 CHF</td>
      <td align="center"><input type="text" size="6" id="total200200" value="0" disabled="true" />
        CHF</td>
    </tr>
    <tr> </tr>
    <tr>
      <td>Mini</td>
    </tr>
    <tr>
      <td class="dcha">65/31 cm</td>
      <td><input type="text" name="m6531" onkeypress="return justNumbers(event, this)" size="3" id="65/31" value="0" onchange="calculo(this.value,precio6531.value,total6531,total);" />
        Stk.</td>
      <td align="center"><input type="hidden" id="precio6531" value="139"/>
        139 CHF</td>
      <td align="center"><input type="text" size="6" id="total6531" value="0" disabled="true" />
        CHF</td>
    </tr>
    <tr>
      <td>Decke/Leintuch</td>
    </tr>
    <tr>
      <td class="dcha">200/140 cm</td>
      <td><input type="text" name="d200140" onkeypress="return justNumbers(event, this)" size="3" id="200/140decke" value="0" onchange="calculo(this.value,precio200140decke.value,total200140decke,total);" />
        Stk. </td>
      <td align="center"><input type="hidden" id="precio200140decke" value="279"/>
        279 CHF</td>
      <td align="center"><input type="text" size="6" id="total200140decke" value="0" disabled="true" />
        CHF</td>
    </tr>
    <tr></tr>
    <tr></tr>
    <tr></tr>
    <tr>
      <td colspan="2"><strong>Total</strong></td>
      <td></td>
      <td align="center"><input type="text"  id="total" size="6" value="0" disabled="true" onchange="multiplicar();" />
        <strong> CHF</strong></td>
    </tr>
    <tr>
      <td colspan="2"><strong>Spezialrabatt 5%</strong></td>
      <td></td>
      <td align="center"><input type="text" id="rabatt" size="6" value="0" disabled="true" />
        <strong> CHF</strong></td>
    </tr>
    <tr>
      <td colspan="3"><strong>Total (inkl. Lieferkosten)</strong></td>
      <td align="center"><input type="text" id="totalwithrabatt" size="6" value="0" disabled="true" />
        <strong> CHF</strong></td>
    </tr>
    <tr></tr>
    <tr ></tr>
    <td colspan="4"><strong>
      <p><a href="lieferumfang.html" target="_blank" style="text-decoration:none" >Lieferumfang</a></p>
    </strong></td>
  </tr>
    <td colspan="4"><strong>
      <h> .</h>
    </strong></td>
  </tr>
  <tr></tr>
  <tr></tr>
  <tr>
    <td colspan="4" style="text-align:left" >&nbsp;</td>
  </tr>
</table>
 
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Formulario de pedido que recalcule el total

Publicado por carmen (2 intervenciones) el 02/09/2014 13:10:47
RESUELTO!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar