Tema: Suma y resta
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/08/2003, 01:40
Avatar de biblio
biblio
 
Fecha de Ingreso: enero-2002
Ubicación: Urano
Mensajes: 577
Antigüedad: 22 años, 4 meses
Puntos: 0
Hola, para los textos he antepuesto txt, la suma y resta funcionan, la mejora al script ya lo haras segun tu necesidad, con esto ya tienes una base. Espero te sirva.

Código:
<html>
<head>
<title>Untitled Document</title>
<script language="JavaScript" type="text/JavaScript">
function _Sum(){
	var newval=0;
	var frm = document.main;
	for(i=0;i< frm.length;i++){
		e=frm.elements[i];
		var aux = "frm.txt"+e.value+".value";
		if (e.type=='checkbox' && e.checked){			
			newval += parseInt(eval(aux),10);
		}else if(e.type=='checkbox' && !e.checked){
			newval -= parseInt(eval(aux),10);
		}
	}
	frm.sum.value = newval;
}
</script>
</head>

<body>
<form action="" method="post" name="main" id="main">
  <p> 
    <input name="chk" type="checkbox" id="chk" onClick="javascript:_Sum();" value="1">
    <input name="txt1" type="text" id="txt1" value="10" readonly="true">
    <br>
    <input name="chk" type="checkbox" id="chk" onClick="javascript:_Sum();" value="2">
    <input name="txt2" type="text" id="txt2" value="15" readonly="true">
    <br>
    <input name="chk" type="checkbox" id="chk" onClick="javascript:_Sum();" value="3">
    <input name="txt3" type="text" id="txt3" value="20" readonly="true">
    <br>
    <input name="sum" type="text" id="sum" value="40">
  </p>
  </form>
</body>
</html>
Saludos

Última edición por biblio; 07/08/2003 a las 01:46