Ver Mensaje Individual
  #5 (permalink)  
Antiguo 24/09/2010, 02:39
galorn
 
Fecha de Ingreso: abril-2010
Ubicación: L'Hospitalet de LLobregat
Mensajes: 43
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: Validacion formulario (varios campos mismo nombre)

Cierto xd se me ha ido la olla...
Ya he puesto var, pero me sigue sin ir. En el html lo tengo declarado en name como array tal y como me han respondido [] y luego en el javascript recorro el array para ir viendo todos y si alguno no coincide, devolver false.

Código HTML:
Ver original
  1. <input type="text" name="nombreParticipanteSesion[]">
Código Javascript:
Ver original
  1. function sessionCreationOnClick(myForm){
  2.     alert("entraaaaaaa");
  3.     if (myForm.tiempoSesion.value.length==0){
  4.                 alert("El valor no puede ser nulo!")
  5.                 myForm.tiempoSesion.focus()
  6.                 return false;
  7.     }else if (myForm.tiempoSesion.value < 10){
  8.                 alert("El numero tiene que ser mayor o igual que 10")
  9.                 myForm.tiempoSesion.focus()
  10.                 return false;
  11.     }
  12.     for (var i=0; i<myForm.nombreParticipanteSesion.length; i++){
  13.                if(myForm.nombreParticipanteSesion[i].value.length==0){
  14.                      alert("El valor del nombe no puede ser nulo!")
  15.                      myForm.nombreParticipanteSesion[i].focus()
  16.                      return false;
  17.                }
  18.         }
  19.     //el formulario se envia si todo ha ido bien
  20.     alert("Muchas gracias por enviar el formulario");
  21.     return true;
  22. }