Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/03/2012, 10:08
Avatar de diamari
diamari
 
Fecha de Ingreso: marzo-2012
Mensajes: 95
Antigüedad: 12 años, 1 mes
Puntos: 30
Respuesta: Una funcion puede funcionar en un arreglo????

No veo exactamente lo que quieres pero según entiendo yo haría algo así:

Código:
<html>
<head>
<title>Ejemplo de Funciones en Arreglos</title>

<script> 
function promedio(estud) { 
	var n1 = 0;
	var n2 = 0;
	var n3 = 0;
	
	n1 = parseFloat(document.getElementById(estud + '[1]').value);
	n2 = parseFloat(document.getElementById(estud + '[2]').value);
	n3 = parseFloat(document.getElementById(estud + '[3]').value);

	document.getElementById(estud+'[4]').value=((n1+n2+n3)/3).toFixed(2);
}
</script> 
</script>
</head>
<body>
	<form id="notas">
		Estudiante 1<br>
		Nota 1<input id=est1[1] type="text" onchange="promedio('est1')"><br>
		Nota 2<input id=est1[2] type="text" onchange="promedio('est1')"><br>
		Nota 3<input id=est1[3] type="text" onchange="promedio('est1')"><br>
		Promedio<input id=est1[4] type="text"><br>
		<br>
		Estudiante 2<br>
		Nota 1<input id=est2[1] type="text" onchange="promedio('est2')"><br>
		Nota 2<input id=est2[2] type="text" onchange="promedio('est2')"><br>
		Nota 3<input id=est2[3] type="text" onchange="promedio('est2')"><br>
		Promedio<input id=est2[4] type="text"><br>
	</form>
</body>
<html>