Ver Mensaje Individual
  #8 (permalink)  
Antiguo 26/01/2008, 10:23
yazo
 
Fecha de Ingreso: abril-2003
Mensajes: 363
Antigüedad: 21 años, 10 meses
Puntos: 3
Re: Incompatibilidad con IE

Hola de nuevo,

Ya siento volver a molestaros, lo anterior está 100% perfecto!!, aunque ahora quería hacer una cosilla que nose si será viable, sería en que en cada linea del presupuesto se calculara el total y después se calculara un total general de todas las línes del presupuesto, el código con el que lo he intentado es el siguiente:

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>
<head>
<title>Crear inputs</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
//Inicializamos el contador
var cont = 0;

//Función Añadir linea
function addLine(ORDEN, DETALLES, CANTIDAD, TARIFA, TOTAL) {
	//Sumanos uno al contador
	cont++;
	
	//Escribimos los ids en una capa
	fi = document.getElementById('capadestino'); // 1
	contenedor = document.createElement('div'); // 2
	contenedor.id = 'div'+cont; // 3
	fi.appendChild(contenedor); // 4
	
	id = document.createElement('input'); // 5
	id.type='hidden';
	id.name='idcrucero'+cont;
	id.id='idcrucero'+cont;
	id.value = cont;
	contenedor.appendChild(id); // 7
	
	tab = document.getElementById('tabla');
	fila = document.createElement('tr');
	
	//Input Tipo
	celdaorden = document.createElement('td')
	tipo=document.createElement('input')
	tipo.type='hidden';
	tipo.name='tipo'+cont;
	tipo.id='tipo'+cont;
	tipo.value = '1';
	celdaorden.appendChild(tipo);
	//Input Orden
	orden = document.createElement('input')
	orden.style.width = '100%';
	orden.name='orden'+cont;
	orden.id='orden'+cont;
	orden.value = ORDEN;
	celdaorden.appendChild(orden);
	fila.appendChild(celdaorden);
	
	//Input detalles
	celdadetalles = document.createElement('td');
	detalles = document.createElement('input');
	detalles.style.width = '100%';
	detalles.name='detalles'+cont;
	detalles.id='detalles'+cont;
	detalles.value = DETALLES;
	celdadetalles.appendChild(detalles);
	fila.appendChild(celdadetalles);
	
	//Input Cantidad
	celdacantidad = document.createElement('td');
	cantidad = document.createElement('input');
	cantidad.style.width = '100%';
	cantidad.name='cantidad'+cont;
	cantidad.id='cantidad'+cont;
	cantidad.value = CANTIDAD;
	//cantidad.setAttribute( 'onkeyup', sumar(cont));
	celdacantidad.appendChild(cantidad);
	fila.appendChild(celdacantidad);
	
	//Input tarifa
	celdatarifa = document.createElement('td')
	tarifa =document.createElement('input') 
	tarifa.style.width = '100px';
	tarifa.name='tarifa'+cont;
	tarifa.id='tarifa'+cont;
	tarifa.value = TARIFA;
	//tarifa.setAttribute( 'onkeyup', sumar(cont));
	celdatarifa.appendChild(tarifa);
	fila.appendChild(celdatarifa);
	
	//Input Total
	celdatotal = document.createElement('td')
	total = document.createElement('input');
	total.style.width = '100%';
	total.name='total'+cont;
	total.id='total'+cont;
	total.value = TOTAL;
	celdatotal.appendChild(total);
	fila.appendChild(celdatotal);
	
	//Boton Borrar
	celdaborrar = document.createElement('td')
	borrar = document.createElement('input')
	borrar.type='button';
	borrar.name='borrar'+cont;
	borrar.id='borrar'+cont;
	borrar.value = 'Borrar';
	borrar.onclick=function() {
		tab = document.getElementById('tabla');
		padre = this.parentNode.parentNode;
		tab.removeChild(padre);
		
		//Restamos uno al contador
		//cont--;
		//actualizamos el contador
		//document.getElementById('contador').value = cont;
	}
	celdaborrar.appendChild(borrar);
	fila.appendChild(celdaborrar);
	tab.appendChild(fila)
	
	//actualizamos el contador
	document.getElementById('contador').value = cont;
}

function sumar(cont){
	var resultado = 0, general = 0;
	var cantidad = cantidad.getElementsByName('cantidad'+cont);
	var tarifa = tarifa.getElementsByName('tarifa'+cont);
	
	// Total de la linea
	resultado = cantidad.value * tarifa.value;
	total.getElementById('total'+cont).value = resultado;

	//Total General
	for(a=0; a<cont; a++){
		general += (parseFloat('total'+cont.value));
	}
	document.getElementById('totalgeneral').value = 5;
}

</script>
</head>
<body>

<form><?php echo "Respuesta:<br><textarea cols=\"50\" rows=\"8\" readonly=\"true\">" . print_r($_POST, true) . "</textarea><br><br>"; ?><br><br></form>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div align='right'><a href='#' onclick='addLine(11, 22, 33, 44, 55);return false'>Añadir Linea +</a></div>
<div id='capadestino'></div><br />
<table width="100%" cellpadding="3" cellspacing="3">

<tr>
<td width="50" align="center"><strong>Orden</strong></td>
<td align="center" width="100%"><strong>Detalles</strong></td>
<td width="50" align="center"><strong>Cantidad</strong></td>
<td width="100" align="center"><strong>Tarifa</strong></td>
<td width="100" align="center"><strong>Total</strong></td>
<td width="50">&nbsp;</td>
</tr>
<tbody id="tabla">
</tbody>
</table>  
Total: <input type='text' value='0' name="total" id='total'>
<input type='hidden' value='0' name="contador" id='contador'>
<input class="boton" name="insertar" type="submit" id="insertar" value="Guardar..." />
</form>

</body>
</html> 
El input totalgeneral está fuera de la tabla, y lo único que tiene que hacer es actualizarse con el total general.

¿Esto se podría hacer?

Gracias por todo.