Codigo Javascript
Código HTML:
// Variable de Conteo de lineas
var lineCount = new Array();
/**
* Agrega una linea de datos a un formulario
* @param string div El ID del div objetivo donde se agrega una linea
* @param string line El ID del div que contiene la linea a agregar
* @param string f Funcion extra para pasarle a los eventos
*/
function addFormLine(div, line, f)
{
var f = (f == null) ? "" : f;
lineCount[div] = lineCount[div] == null ? 1 : lineCount[div] + 1;
var mySelf = div + "_line_" + lineCount[div];
var myNum = lineCount[div];
var divTarget = document.getElementById(div);
var divLine = document.getElementById(line).innerHTML;
var divTitle = document.getElementById(line).getAttribute('title');
var newDiv = document.createElement('div');
newDiv.className = 'row';
newDiv.setAttribute('id', mySelf);
divLine = divLine.replace(/mySelf/g, mySelf);
newDiv.innerHTML = divLine;
newDiv.innerHTML += "<div class=\"cell\"><img style=\"cursor: pointer;\" src=\"../images/remove.gif\" border=\"0\" onclick=\"removeFormLine(\'" + mySelf + "\');" + f + "\"></div>";
if (divTitle != null && divTarget.hasChildNodes() == false){
var titles = divTitle.split(",");
var newTitle = document.createElement('div');
newTitle.className = 'row';
for (i = 0; i < titles.length; ++i){
var titleSize = titles[i].match(/\(\w+\)/,'');
titleSize = titleSize[0].replace(/[\(\)]/g,'');
var titleName = titles[i].replace(/\(\w+\)/,'');
newTitle.innerHTML += "<div class=\"title\" style=\"width: " + titleSize + "px;\">" + titleName + "</div>";
}
divTarget.appendChild(newTitle);
divTarget.setAttribute('cab', '1');
}
divTarget.appendChild(newDiv);
//Imprime el total de filas
document.form1.totalfilas.value=myNum;
}
/**
* Elimina una linea de un formulario
* @param string div El ID del div que se quiere eliminar
*/
function removeFormLine(div)
{
var parentName = div.replace(/_line_\w+/g, '');
var divParent = document.getElementById(parentName);
var divTarget = document.getElementById(div);
var hasTitle = divParent.getAttribute('cab');
divParent.removeChild(divTarget);
if (hasTitle != null && divParent.childNodes.length == 1){
divParent.innerHTML = "";
}
//Imprime el total de filas
document.form1.totalfilas.value=document.form1.totalfilas.value-1;
}
Codigo html
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="form_dinamico_asiento.js"></script> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <form name="form1" method="post" action=""> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <th scope="col"><a href="javascript:addFormLine('myDiv', 'myLine');" class="TextoContenidoTabla">Agregar Linea +</a></th> </tr> <tr> <th scope="row"> <div id="myDiv"></div> <div id="myLine" class="hide" title="CÓDIGO(80),DESCRIPCIÓN (307),DEBE(78),HABER(80)"> <div> <input type="text" name="codigo" id="codigo" maxlength="12" style="width: 81px" class="TextoContenidoTabla"> </div> <div> <input type="text" name="descripcion" id="descripcion" maxlength="11" style="width: 310px" class="TextoContenidoTabla"> </div> <div> <input type="text" name="debe" id="debe" style="width: 80px" class="TextoContenidoTabla" value="0"> </div> <div> <input type="text" name="haber" id="haber" style="width: 80px" class="TextoContenidoTabla" value="0" > </div> </div> <input name="totalfilas" id="totalfilas" type="hidden"> </th> </tr> </table> </form> </body> </html>
el contador de filas de los div en javascript de la grilla myNum
Por ejemplo: id="codigo"+myNum;
asi pero dentro del formulario, en cada fila el id= codigo1, codigo2, codigo3, ... codigoN;
Por favor ayúdenme
muchas gracias
Necesito esas variables, para hacer cálculos matemático


