Foros del Web » Programando para Internet » Javascript »

No me funciona este codigo ayuda!!!!!!!!!!!!!!!

Estas en el tema de No me funciona este codigo ayuda!!!!!!!!!!!!!!! en el foro de Javascript en Foros del Web. HOLA A TODOS!!!!!!! TENGO ESTE CODIGO PERO NO ME FUNCIONA ESPARA PROMEDIAR 3 VALORES <?php echo '<script languaje="JavaScript" > function Sumar(){ interval = setInterval("calcular()",1); } ...
  #1 (permalink)  
Antiguo 28/06/2010, 11:11
 
Fecha de Ingreso: diciembre-2009
Mensajes: 48
Antigüedad: 14 años, 4 meses
Puntos: 0
No me funciona este codigo ayuda!!!!!!!!!!!!!!!

HOLA A TODOS!!!!!!!

TENGO ESTE CODIGO PERO NO ME FUNCIONA ESPARA PROMEDIAR 3 VALORES

<?php

echo '<script languaje="JavaScript" >

function Sumar(){
interval = setInterval("calcular()",1);
}
function calcular(){
uno = document.autoSumForm.calif1.value;
dos = document.autoSumForm.calif2.value;
tres = document.autoSumForm.calif3.value;


document.autoSumForm.promedio.value = (((uno * 1) + (dos * 1) + (tres * 1))/3);
}
function NoSumar(){
clearInterval(interval);
}
</script>';


echo "<td><input type=text id='calif1' name='calif1' size='5' value='2' onFocus='Sumar();' onBlur='NoSumar();'></td>";
echo "<td><input type=text id='calif2' name='calif2' size='5' value='2' onFocus='Sumar();' onBlur='NoSumar();'></td>";
echo "<td><input type=text id='calif3' name='calif3' size='5' value='' onFocus='Sumar();' onBlur='NoSumar();'></td>";

echo "<td><input type=text name='promedio' MAXLENGTH='3' size='5' ></td>";



?>



GRACIAS.......
  #2 (permalink)  
Antiguo 28/06/2010, 11:39
Avatar de wiwi74  
Fecha de Ingreso: marzo-2008
Mensajes: 515
Antigüedad: 16 años, 1 mes
Puntos: 10
Respuesta: No me funciona este codigo ayuda!!!!!!!!!!!!!!!

Te falta esto:

Código PHP:

echo "<form name='autoSumForm'";

//.....

echo "</form>"
Funciona...

Última edición por wiwi74; 28/06/2010 a las 13:36
  #3 (permalink)  
Antiguo 28/06/2010, 11:47
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Tema movido desde PHP a Javascript
  #4 (permalink)  
Antiguo 28/06/2010, 13:01
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: No me funciona este codigo ayuda!!!!!!!!!!!!!!!

Hola

A ver si esto te ayuda

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function calcular(cual) {
  5. valores = new Array();
  6. for (i = 0, campos = document.frm[cual].length; i < campos; i++) {
  7. valores[valores.length] = document.frm[cual][i].value;
  8. }
  9.  
  10. var promedio = 0;
  11. for (i = 0; i < valores.length; i++) {
  12. promedio += (valores[i]/3);
  13. }
  14. document.frm['prom_'+cual].value = (promedio).toFixed(2);
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <form name="frm">
  20. <b>Notas 1</b><br />
  21. Lenguaje: <input type="text" value="" name="nota_1" onkeyup="calcular(this.name)" ><br />
  22. Inglés: <input type="text" value="" name="nota_1" onkeyup="calcular(this.name)" ><br />
  23. Matemáticas: <input type="text" value="" name="nota_1" onkeyup="calcular(this.name)" ><br />
  24. Promedio: <input type="text" value="" name="prom_nota_1">
  25.  
  26. <br /><br />
  27. <b>Notas 2</b><br />
  28. Lenguaje: <input type="text" value="" name="nota_2" onkeyup="calcular(this.name)" ><br />
  29. Inglés: <input type="text" value="" name="nota_2" onkeyup="calcular(this.name)" ><br />
  30. Matemáticas: <input type="text" value="" name="nota_2" onkeyup="calcular(this.name)" ><br />
  31. Promedio: <input type="text" value="" name="prom_nota_2">
  32. </form>
  33. </body>
  34. </html>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:06.