Tengo un formulario con 2 campos y los datos que guardo me muestra en una tabla que se carga dinamicamente a traves de AJAX, mi pregunta es si existe algun modo de llenar esta tabla sin insertar los datos en MySQL?. Lo que intento hacer es un proceso de facturacion donde ingrese varios items y luego con otro boton guardar los datos rellenados en esa tabla y demas campos que yo vaya a ir agregando, coloco aqui los archivos que estoy usando:
DPMOVINV_FRONT.PHP
Código HTML:
 <!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>Documento sin título</title> <script type="text/javascript" src="ajax.js"></script> </head> <body> <form name="productos" action="" onsubmit="enviarDatos(); return false" > <table width="200" border="0"> <tr> <td bgcolor="#CCCCCC" ><label>Codigo:</label></td> <td bgcolor="#CCCCCC" ><label><input type="text" name="codigo" size="15" ></label></td> <td bgcolor="#CCCCCC" ><label>Cantidad:</label></td> <td bgcolor="#CCCCCC" ><label><input type="text" name="cantidad" size="10" ></label></td> </tr> </table> <label> <input type="submit" name="Submit1" value="Grabar" /> </label> <label> <input type="submit" name="borrar" value="Cancelar" /> </label> </form> <p> <div id="resultado"> <?php include('tabla.php') ?> </div> </body> </html>
Código Javascript:
Ver original
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function enviarDatos(){
//donde se mostrará lo resultados
divResultado = document.getElementById('resultado');
//valores de los inputs
cod=document.productos.codigo.value;
cant=document.productos.cantidad.value;
//instanciamos el objetoAjax
ajax=objetoAjax();
//uso del metodo POST
//archivo que realizará la operacion
ajax.open("POST","dpmovinv.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta capa
divResultado.innerHTML = ajax.responseText
//llamar a funcion para limpiar los inputs
LimpiarCampos();
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax.send("&codigo="+cod+"&cantidad="+cant)
}
function LimpiarCampos(){
document.productos.codigo.value="";
document.productos.cantidad.value="";
document.productos.codigo.focus();
}
TABLA.PHP
Código PHP:
   
<?php
 
include('conex.php');
 
 
$sql=mysql_query("SELECT MOV_ITEM,MOV_CODIGO,MOV_CANTID FROM dpmovinvtempo");
 
?>
<table style="border:1px solid #FF0000; color:#000;width:760px;">
<tr style="background:#1c68be;">
    <td>Item</td>
    <td>Codigo</td>
    <td>Cantidad</td>
    
</tr>
 
<?php
 
while($row = mysql_fetch_array($sql))
{
    echo "    <tr>";
    echo "         <td>".$row['MOV_ITEM']."</td>";
    echo "         <td>".$row['MOV_CODIGO']."</td>";
    echo "         <td>".$row['MOV_CANTID']."</td>";
    echo "    </tr>";
}
?>
</table>   Código PHP:
  
<!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>Documento sin título</title>
</head>
 
<body>
 
<?php
 
include('conex.php');
$cod=$_POST['codigo'];
$cant=$_POST['cantidad'];
$item = $item + 1;
 
$sql = "INSERT INTO dpmovinvtempo (MOV_ITEM,MOV_CODIGO,MOV_CANTID) VALUES ('$item','$cod','$cant') ";
 
mysql_query($sql);
 
include('tabla.php');
 
?>
 
</body>
</html>    
 



