Ver Mensaje Individual
  #5 (permalink)  
Antiguo 07/02/2014, 05:15
radvla
 
Fecha de Ingreso: agosto-2013
Mensajes: 40
Antigüedad: 10 años, 8 meses
Puntos: 0
Respuesta: usando onsubmit no me valida el formulario

sigo aislando el problema.Esta funcion verificar1 me da los alert segun lo previsto e impide el envío del formulario:

<script language="javascript">
function verificar1() {

alert("estoy en la función");
valor1=document.getElementById("BIEN_SERVICIO_UNO" ).value;
alert("EL CAMPO UNO ESTÁ con longitud=");
alert(valor1);
valor2=document.getElementById("BIEN_SERVICIO_DOS" ).value;
alert("EL CAMPO DOS ESTÁ con longitud=");
alert(valor2);
valor3 = document.getElementById("BIEN_SERVICIO_TRES").valu e;
alert("he recogido el campo TREScon longitud=");
alert(valor3);


return false;
}
</script>

en cambio si añado un if para ver si hay un campo en blanco se interrumpe la función, no devueleve el valorfalse y se envía el formulario:


<script language="javascript">
function verificar1() {

alert("estoy en la función");
valor1=document.getElementById("BIEN_SERVICIO_UNO" ).value;
alert("EL CAMPO UNO ESTÁ con longitud=");
alert(valor1);
valor2=document.getElementById("BIEN_SERVICIO_DOS" ).value;
alert("EL CAMPO DOS ESTÁ con longitud=");
alert(valor2);
valor3 = document.getElementById("BIEN_SERVICIO_TRES").valu e;
alert("he recogido el campo TREScon longitud=");
alert(valor3);

if( valor3 == null || valor3.length == 0 || /^\s+$/.test(valor3) ) {
ALERT("EL CAMPO TRES ESTÁ VACIO");
return false;
}
return false;
}
</script>