
06/02/2008, 02:32
|
| | Fecha de Ingreso: noviembre-2005
Mensajes: 405
Antigüedad: 19 años, 4 meses Puntos: 0 | |
Añado mi código Re: Añadir campos dinámicamente Buenas,
Ayer noche realicé un codigo, a apartir de aqui lo que necesito y me quedo atascado es lo siguiente:
En el enlace "Buscar" te abre un POP para buscar articulos, y cuando yo selecciono uno, en la pantalla anterior que se añada el código, descripción y precio en los testBox, y esto para los diferentes "Buscar" creados dinámicamente.
<html>
<head>
<title>Test</title>
</head>
<script>
var number ="100";
function eliminarAll(){
var tbody = document.getElementById("table1").getElementsByTag Name("tbody")[0];
while (tbody.hasChildNodes()) {
tbody.removeChild(tbody.firstChild);
}
}
function eliminar(idRow)
{
nodoTabla = document.getElementById(idRow);
nodoTabla.parentNode.removeChild(nodoTabla);
}
function addTextBox()
{
number++;
var tbody = document.getElementById("table1").getElementsByTag Name("tbody")[0];
var row = document.createElement("tr");
var cell1 = document.createElement("td");
cell1.style.border="0px";
cell1.style.cellspacing="0px";
cell1.style.cellpadding="0px";
var papelera = document.createElement("a");
var img = document.createElement("IMG");
img.src="../tools/img/papelera.gif";
img.border=0;
img.alt="Eliminar";
papelera.appendChild(img);
papelera.href="javascript:eliminar('"+number+"');" ;
cell1.appendChild(papelera);
var espacio = document.createElement("IMG");
espacio.border=1
espacio.src="transparent.gif";
espacio.width="15px";
cell1.appendChild(espacio);
var inputTextCodigo = document.createElement("INPUT");
inputTextCodigo.type = "text";
inputTextCodigo.name = "textCodigo[" + number + "]";
inputTextCodigo.size = 15;
//inputTextCodigo.value = "textCodigo[" + number + "]";
cell1.appendChild(inputTextCodigo);
var espacio = document.createElement("IMG");
espacio.border=1
espacio.src="transparent.gif";
espacio.width="15px";
cell1.appendChild(espacio);
var inputTextDescr = document.createElement("INPUT");
inputTextDescr.type = "text";
inputTextDescr.name = "textDescripcion[" + number + "]";
inputTextDescr.size = 70;
//inputTextDescr.value = "textDescripcion[" + number + "]";
cell1.appendChild(inputTextDescr);
var espacio = document.createElement("IMG");
espacio.border=1
espacio.src="transparent.gif";
espacio.width="15px";
cell1.appendChild(espacio);
var inputTextCantidad = document.createElement("INPUT");
inputTextCantidad.type = "text";
inputTextCantidad.name = "textTextCantidad[" + number + "]";
inputTextCantidad.size = 20;
//inputTextCantidad.value = "textTextCantidad[" + number + "]";
cell1.appendChild(inputTextCantidad);
var newLink=document.createElement('a');
newLink.setAttribute('href','buscar.html');
newLink.setAttribute('target','_blank');
newLink.className='contrast';
var linkText=document.createTextNode('buscar');
newLink.appendChild(linkText);
cell1.appendChild(newLink);
row.appendChild(cell1);
row.id = number;
tbody.appendChild(row);
}
</script>
<body>
<table border="1" width="100%">
<tr>
<td width="16%">Código</td>
<td width="47%">Descripción</td>
<td width="">Cantidad</td>
</tr>
<tr>
<td colspan="6">
<table id="table1" style="border:1px;cellspacing:0px;cellpadding:0px; " border="0">
<tbody></tbody>
</table>
</td>
</tr>
<tr>
<td colspan="5">
<input type="text" size="10" maxlength="10">
<a href="javascript:addTextBox();">Añadir Articulos</a>
<img src="transparent.gif" width="10%" border="0" height="1">
<a href="javascript:eliminarAll();">Eliminar todos</a>
</td>
</tr>
</table>
</body>
</html> |