Si triby, lo hice intentando hacer laconexion una sola vez y ni asi me funciona,
mira no se hacerlo como dices, con arrays, mi problema es que tengo que hacer una factura, esa factura puede tener N registros como sabemos,
entonces tengo un boton para crear cada caja de texto, las sumas de las cajas etc,
pero no se como insertar esos registros a la vez, podrias ayudarme??, este es el codigo completo de la pagina
Código:
<script language="javascript" type="text/javascript">
var indiceFilaFormulario = 1;
function addCampo(){
newFila = document.getElementById("formCampos").insertRow(-1);
newFila.id = indiceFilaFormulario;
newCelda = newFila.insertCell(-1);
newCelda.innerHTML = "<td><label>" +indiceFilaFormulario+ "</label></td>";
newCelda = newFila.insertCell(-1);
newCelda.innerHTML = "<td><input type = 'text' name = 'cantidad["+indiceFilaFormulario+"]' size='5' maxlength='5' class='mayus'></td>";
newCelda = newFila.insertCell(-1);
newCelda.innerHTML = "<td><textarea name = 'descripcion["+indiceFilaFormulario+"]' cols='40' rows='5' class='mayus'></textarea></td>";
newCelda = newFila.insertCell(-1);
newCelda.innerHTML = "<td><input type = 'text' name = 'tiempoEntrega["+indiceFilaFormulario+"]' size='10' maxlength='10' class='mayus'></td>";
newCelda = newFila.insertCell(-1);
newCelda.innerHTML = "<td><input type = 'text' name = 'precioUnitario["+indiceFilaFormulario+"]' size='10' maxlength='10' ></td>";
newCelda = newFila.insertCell(-1);
newCelda.innerHTML = "<td><input type = 'text' name = 'costoTotal["+indiceFilaFormulario+"]' size='10' maxlength='10'></td>";
newCelda = newFila.insertCell(-1);
newCelda.innerHTML = "<th><input type = 'button' value='Eliminar' onclick='delCampo(this)' ></th>";
indiceFilaFormulario++;
incr++;
}
function delCampo(obj){
var oTr = obj;
while (oTr.nodeName.toLowerCase()!='tr'){
oTr = oTr.parentNode;
}
var root = oTr.parentNode;
root.removeChild(oTr);
indiceFilaFormulario--;
}
function calcular(){
for(j=0;j<indiceFilaFormulario;j++){
cant = document.cotiza.cantidad+indiceFilaFormulario+.value;
precUnit = document.cotiza.precioUnitario+indiceFilaFormulario+.value;
document.cotiza.costoTotal+indiceFilaFormulario+.value = (cant * precUnit);
document.cotiza.subTotal.value = (document.cotiza.costoTotal+indiceFilaFormulario+.value) + (document.cotiza.costoTotal+indiceFilaFormulario+.value);
document.cotiza.Total.value = (document.cotiza.subTotal.value * .15) + (document.cotiza.subTotal.value);
}
}
// AQUI LA FUNCTION GUARDAR CON UN UNICO CONTROLADOR, NO LA PUSE PUES YA NO CABE
</script>
<!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>Cotizaciones</title>
<style type="text/css">
<!--
.Estilo3 {
font-size: 14px
}
.Estilo5 {font-size: 14}
.Estilo7 {
font-size: 16px;
font-weight: bold;
}
.Estilo9 {
font-size: 12px;
font-weight: bold;
}
.Estilo10 {font-size: 12px}
.Estilo14 {
font-size: 20px;
font-weight: bold;
}
-->
</style>
</head>
<body onLoad="document.cotiza.noCotizacion.focus()">
<style type="text/css">
.mayus {
text-transform: uppercase;
}
</style>
<form id="cotiza" name="cotiza" method="post" >
<table width="852" height="970"border="1" align="center" bordercolor="#000000">
<tr>
<td width="173" height="150" rowspan="3"><p class="Estilo3"><br />
<input type="hidden" name="IdCotizacion" id="IdCotizacion" />
</p> </td>
<td colspan="4" rowspan="3"><div align="center" class="Estilo3"><a href="/SCI/index.php"></a></div></td>
<td height="31" colspan="3"> </td>
</tr>
<tr>
<td width="34" height="26"><div align="center" class="Estilo3">e-mail: </div></td>
<td colspan="2"> </td>
</tr>
<tr>
<td height="40" colspan="3"><div align="center" class="Estilo3"></div></td>
</tr>
<tr>
<td height="9"><span class="Estilo9">Compañia:</span></td>
<td colspan="4"><label>
<input name="compania" type="text" id="compania" tabindex="1" value="" size="50" class="mayus"/>
</label></td>
<td colspan="3" rowspan="5">No. Cotización:
<label>
<input type="text" name="noCotizacion" id="noCotizacion" />
</label></td>
</tr>
<tr>
<td height="17"><span class="Estilo10">AT'N:</span></td>
<td colspan="4"><label>
<input name="atiende" type="text" id="atiende" tabindex="2" size="50" class="mayus"/>
</label></td>
</tr>
<tr>
<td height="17"><span class="Estilo10">C.C:</span></td>
<td colspan="4"><label>
<input name="conCopia" type="text" id="conCopia" tabindex="3" size="50" class="mayus"/>
</label></td>
</tr>
<tr>
<td height="17"><span class="Estilo10">FECHA (dd / mm / aaaa):</span></td>
<td width="63">
<div align="center">
<input name="fechaD" type="text" id="fechaD" tabindex="4" size="3" maxlength="2" />
/ </div></td>
<td width="60"><div align="center">
<input name="fechaM" type="text" id="fechaM" tabindex="5" size="3" maxlength="2" />
/</div></td>
<td width="42"><div align="center">
<input name="fechaA" type="text" id="fechaA" tabindex="6" size="5" maxlength="4" />
</div></td>
<td width="288"> </td>
</tr>
<tr>
<td height="17"><span class="Estilo10">DE:</span></td>
<td colspan="4"> </td>
</tr>
<tr>
<td height="26" colspan="8"><div align="center"><span class="Estilo7">C O T I Z A C I O N</span></div></td>
</tr>
<tr>
<td height="291" colspan="8" align="left" valign="top">
<label></label> <label></label> <label></label> <label></label> <label></label>
<table width="842" border="0" id="formCampos">
<tr>
<th width="49" scope="col"><div align="center">No</div></th>
<th width="70" scope="col"><div align="center">Cantidad</div></th>
<th width="426" scope="col"><div align="center">Modelos / Descripción</div></th>
<th width="129" scope="col"><div align="center">Tiempo de Entrega</div></th>
<th width="81" scope="col"><div align="center">Precio Unitario</div></th>
<th scope="col"><div align="center">Costo Total</div></th>
</tr>
</table>
<br />
<label>
<input type="button" onClick="addCampo();" value="Agregar Campo" />
</label></td>
</tr>
<tr>
<td height="96" colspan="6" rowspan="4"><div align="center"><span class="Estilo14">"HERRAMIENTA A TIEMPO PRODUCCION SEGURA"</span></div></td>
<td height="9" colspan="2">
<div align="center">
<input name="calcular" type="button" class="Estilo14" id="calcular" value="Calcular" onclick="calcular();" />
</div>
</td>
</tr>
<tr>
<td width="77" height="10"><strong>SUBTOTAL</strong></td>
<td width="63" align="center"><input name="subtotal" type="text" id="subtotal" tabindex="13" size="10" readonly="readonly" /></td>
</tr>
<tr>
<td height="21"><span class="Estilo3"><strong>I.V.A.</strong></span></td>
<td align="left"><div align="center">15%</div></td>
</tr>
<tr>
<td height="21"><span class="Estilo3"><strong>TOTAL</strong></span></td>
<td align="center">
<input name="total" type="text" id="total" tabindex="14" size="10" readonly="readonly"/> </td>
</tr>
<tr>
<td height="23" colspan="8">*** Vigencia de la cotizaciòn 15 dìas apartir de la fecha de envio </td>
</tr>
<tr>
<td height="23" colspan="8">*** Una vez autorizada y colocada la orden de compra NO se aceptan cancelaciones después de 24:00 hras.</td>
</tr>
<tr>
<td height="23" colspan="8">*** En todas las Herramientas Especiales NO se aceptan devoluciones, ya que son NO cancelables y NO retornables.</td>
</tr>
<tr>
<td height="42" colspan="8"> *** En productos especiales nos reservamos el derecho de entrega +/-10% de la cantidad ordenada.</td>
</tr>
<tr>
<td height="23" colspan="8">Los precios son en<strong>
<label>
<select name="tipoCambio" id="tipoCambio">
<option value="1">Moneda Nacional</option>
<option value="2">Dolares</option>
</select>
</label>
</strong></td>
</tr>
<tr>
<td height="23" colspan="8"><div align="center"><span class="Estilo5">*Le agradecemos la oportunidad de cotizarle, estamos a sus órdenes para cualquier información complementaria*</span></div></td>
</tr>
</table>
<p>
<label>
<input type="button" onclick="guardar();" value="Generar Archivo" />
</label>
</p>
</form>
<p align="center"><a href="/SCI/index.php">Pagina Principal</a></p>
</body>
</html>