Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/02/2014, 15:35
Pantaláimon
 
Fecha de Ingreso: julio-2006
Ubicación: Barcelona
Mensajes: 244
Antigüedad: 17 años, 9 meses
Puntos: 32
Cambiar modo de interacción interactivamente

Buenas.

Estaba haciendo una prueba con el parámetro evento del método addEventListener. Tengo el siguiente código HTML:
Código HTML:
Ver original
  1. <form method="get" action="" name="suma">
  2.     <select name="eventType">
  3.         <option value="submit">submit</option>
  4.         <option value="input" >input</option>
  5.     </select>
  6.     <input type="text" name="num1" />
  7.     +
  8.     <input type="text" name="num2" />
  9.     =
  10.     <output name="result"></output>
  11.     <input type="submit" value="resultado"/>
  12. </form>
Tengo un campo select que según si está seleccionada la opción submit o input quiero que el formulario responda al evento submit o input, respectivamente. Aquí el código javascript:
Código Javascript:
Ver original
  1. window.addEventListener( "load", function(){
  2.  
  3.     var formSuma  = document.forms.suma;
  4.     var eventType = formSuma.eventType.value;
  5.     formSuma.eventType.addEventListener( "change", function(){
  6.         console.log( formSuma.eventType.value );
  7.     });
  8.  
  9.     formSuma.addEventListener( formSuma.eventType.value, function(){
  10.         console.log( "eo" );
  11.     });
  12. });
Sin embargo, independientemente del valor de select el formulario siempre responde en caso de hacer un submit. Dejo también el ejemplo en jsfiddle: http://jsfiddle.net/ESdav/

¿Alguien sabría cuál es el problema? Gracias!
__________________
github.com/xgbuils | npm/xgbuils