
Guardar datos dinamicos en tablas
Publicado por Rouse (5 intervenciones) el 27/05/2014 02:22:00
Holis plis ayuda urgente necesito guardar estos datos dinámicos en una tabla mysql. Yo inserto filas que contiene producto, cantidad y valor en una <table> de html. El código funciona correctamente pero no se como coger cada uno de los datos de la columna producto, cantidad, precio, subtotal. De antemano gracias.
Ahi muestro una imagen

este es el código para copiar y probar
Ahi muestro una imagen

este es el código para copiar y probar
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Factura</title>
<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,valor,iva,totales,descuento) {
fila = obj.parentNode.parentNode;
document.getElementById('tabla').removeChild(fila);
total = total - valor;
$("#txttotal").val(total);
iva = total * 0.19;
$("#txtiva").val(iva);
totales=total + iva- descuento ;
$("#txttotales").val(totales);
}
</script>
</head>
<body>
<form name='form1' id='form1' action='guardar.php' method='post'>
<table width='90%' height='180' align='center' class='tabl' >
<!--Ingreso de productos cantidad y valor -->
<tr>
<td>PRODUCTO</td>
<td><input type='text' name='txtNombres' id='txtNombres' /></div></td>
<td>CANTIDAD</td>
<td><input type='text' name='txtApellidos' id='txtApellidos'/></td>
<td>VALOR</td>
<td><input type='text' name='txtTelefono' id='txtTelefono' /><input name="btnInsertar" id="btnInsertar" type="button" value="Insertar" class="" /></td>
</tr>
</table>
<table width='90%' height='' align='center' bgcolor='#FFFFFF' class='tabl' id="tblDatos" >
<tbody id="tabla">
<tr>
<td><strong>Producto</strong></td>
<td><strong>Cantidad</strong></td>
<td><strong>Precio</strong></td>
<td><strong>Subtotal</strong></td>
<td><strong>Eliminar</strong></td>
</tr>
<!--Insertar los datos en la tabla -->
<script type="text/javascript" charset="utf-8">
var total = 0;
var iva = 0;
var totales = 0;
var i = 0;
$(function() {
$("#btnInsertar").click(addUsuario);
});
function addUsuario(){
var Nombres=$('#txtNombres').val();
var apellidos=$("#txtApellidos").val();
var telefono=$("#txtTelefono").val();
var descuento=$("#txtDescuento").val();
var tablaDatos= $("#tblDatos");
var valor=(apellidos*telefono)
if(Nombres!="" || apellidos!="" || telefono!="" ){
tablaDatos.append("<tr><td><input type='text' name='fruit[]' value='"+Nombres+"' autofocus readonly style='background-color:#FFF' /></td><td><input type='text' name='cantidad[]' value='"+apellidos+"' autofocus readonly style='background-color:#FFF' aling='center' 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,"+valor+","+iva+","+totales+","+descuento+")' value='ELIMINAR' /></td><td><input type='hidden' name='valor[]' value='"+descuento+"'/></td></tr>");
total = total + valor;
iva = total * 0.19;
totales=total + iva - descuento
$("#txttotal").val(total);
$("#txtiva").val(iva);
$("#txtdescuento").val(descuento);
$("#txttotales").val(totales);
reset_campos();
}
}
function reset_campos(){
$("#txtNombres").val("");
$("#txtApellidos").val("");
$("#txtTelefono").val("");
}
$(".delete").live('click', function(event) {
$(this).parent().parent().remove(tr);
});
</script>
</tbody>
</table>
</form>
</body>
</html>
Valora esta pregunta


0