
sumar input en javascript dinamicamente
Publicado por Daniel (8 intervenciones) el 28/11/2013 15:42:30
hola amigos. Soy nuevo en este foro.espero me puedan ayudar.
tengo este codigo que funciona perfectamente. Si lo ejecutan en una archivo.php se daran cuenta que me falta obtener el total de todos los productos.
tengo este codigo que funciona perfectamente. Si lo ejecutan en una archivo.php se daran cuenta que me falta obtener el total de todos los productos.
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
<!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>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="Plugin Gratis para autocompletar un input con jQuery y Ajax" name="description" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.js" charset="utf-8"></script>
<script src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">
function borrar(obj) {
fila = obj.parentNode.parentNode;
document.getElementById('tabla').removeChild(fila);
}
</script>
<link href="estilotablas.css" rel="stylesheet" type="text/css" />
<style type="text/css">
@import url("autocomplete.css");
</style>
</head>
<body>
<form name='form1' id='form1' action='ejemplo.php' method='post'>
<table width='90%' height='180' align='center' bgcolor='#FFFFFF' class='tabl' border="1">
<tr class='tr'>
<td colspan='6' align='center' class='td'>INGRESO DE PRODUCTOS A BODEGA</td>
</tr>
<tr>
<td class='td1'> PRODUCTO</td>
<td class='td1'><div class="autocomplete" ><input type='text' name='txtNombres' id='txtNombres' size="30" data-source="search.php?search=" /></div></td>
<td class='td1'>CANTIDAD</td>
<td class='td1'><input type='text' name='txtApellidos' id='txtApellidos' size='30' class='Campo' /></td>
<td class='td1'>VALOR</td>
<td class='td1'><input type='text' name='txtTelefono' id='txtTelefono' size='20' class='Campo' /><input name="btnInsertar" id="btnInsertar" type="button" value="INSERTAR" class="" /></td>
</tr>
</table>
<br />
<table width='90%' height='' align='center' bgcolor='#FFFFFF' class='tabl' id="tblDatos" border="1">
<tbody id="tabla">
<tr class='tr'>
<td align='center' class='td'><strong>Producto</strong></td>
<td align='center' class='td'><strong>Cantidad</strong></td>
<td align='center' class='td'><strong>Precio</strong></td>
<td align='center' class='td'><strong>Subtotal</strong></td>
<td align='center' class='td'><strong>Eliminar</strong></td>
</tr>
<script type="text/javascript" charset="utf-8">
$(function() {
$("#btnInsertar").click(addUsuario);
});
function addUsuario(){
var Nombres=$('#txtNombres').val();
var apellidos=$("#txtApellidos").val();
var telefono=$("#txtTelefono").val();
var tablaDatos= $("#tblDatos");
var valor=(apellidos*telefono);
if(Nombres!="" || apellidos!="" || telefono!="" ){
tablaDatos.append("<tr><td><input type='text' value='"+Nombres+"' /></td><td><input type='text' name='cantidad[]' value='"+apellidos+"' autofocus readonly style='background-color:#FFF' class='Campo'/></td><td><input type='text' name='precio[]' value='"+telefono+"' autofocus readonly style='background-color:#FFF' class='Campo' /></td><td><input type='text' name='valor[]' value='"+valor+"' autofocus readonly style='background-color:#FFF' class='Campo'/></td><td align='center'><input type='button' onclick='borrar(this)' value='ELIMINAR' /></td></tr>");
reset_campos();
}
}
function reset_campos(){
$("#txtNombres").val("");
$("#txtApellidos").val("");
$("#txtTelefono").val("");
}
$(".delete").live('click', function(event) {
$(this).parent().parent().remove(tr);
});
</script>
</tbody>
</table>
<BR />
<table width='30%' height='' style="float:right; margin-right:65px" class='tabl' id="tblDatos">
<tr class='tr'>
<td align='center' class='td'><b>TOTAL</b></td>
</tr>
<tr class='tr'>
<td align='center' ><input type="text" name="txttotal" id="txttotal" value="" /></td>
</tr>
<tr class='tr'>
<td align='center' ><input type='submit' value='GRABAR DATOS' name='btnenv' id='btnenv' class='button' /></td>
</tr>
</table>
</form>
</body>
</html>
Valora esta pregunta


0