Foros del Web » Programando para Internet » Javascript »

Validar submit

Estas en el tema de Validar submit en el foro de Javascript en Foros del Web. hola,mi pagina tiene 3 submit,pero al momento de ingresar informacion,no es necesario hacerlo con los tres submit,en donde cada caja de texto pertenece a un ...
  #1 (permalink)  
Antiguo 14/03/2006, 15:42
 
Fecha de Ingreso: febrero-2006
Mensajes: 446
Antigüedad: 18 años, 2 meses
Puntos: 3
Validar submit

hola,mi pagina tiene 3 submit,pero al momento de ingresar informacion,no es necesario hacerlo con los tres submit,en donde cada caja de texto pertenece a un submit.

Yo quiero que al momento de ingresar la informacion,obligue al usuario como minimo a ingresar algo en una de las tres cajas de texto,y dejando en blanco las otras dos.

¿Como puedo obligar al usuario a ingresar informacion,por lo menos en una caja de texto?
gracias

Código:
<html>
<form name=formulario action=pagina.php method=post>

<INPUT type="text" name="fichas_azules"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha" value="ingreso_ficha">

<INPUT type="text" name="fichas_rojas"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha1" value="ingreso_ficha1">

<INPUT type="text" name="fichas_verdes"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha2" value="ingreso_ficha2">
</form>
</html>
  #2 (permalink)  
Antiguo 14/03/2006, 17:28
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Hola:

Trataré de hacerlo de memoría (puedo equivocarme)

funcion alMenosUno(a, b, c) {
return (a != "" || b != "" || c != "");
}

Y el chequeo...

<form name="formulario" action="pagina.php" method="post"
onsubmit="return alMenosUno(fichas_azules.value, fichas_verdes.value, fichas_rojas.value)" >

Si quisieras mensajitos y focos habría que ampliar algo la función.

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #3 (permalink)  
Antiguo 14/03/2006, 20:20
 
Fecha de Ingreso: febrero-2006
Mensajes: 446
Antigüedad: 18 años, 2 meses
Puntos: 3
No me resulta
Código:
<html>
<title>pagina</title>
<head>
<script>
funcion alMenosUno(a, b, c) {
return (a != "" || b != "" || c != "");
}
</script>

</head>
<body>


<form name=formulario action=pagina.php method=post>
<INPUT type="text" name="fichas_azules"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha" value="ingreso_ficha"
onsubmit="return alMenosUno(fichas_azules.value,fichas_verdes.value, fichas_rojas.value)">

<INPUT type="text" name="fichas_rojas"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha1" value="ingreso_ficha1">

<INPUT type="text" name="fichas_verdes"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha2" value="ingreso_ficha2">
</form>
</body>
</html>
  #4 (permalink)  
Antiguo 15/03/2006, 14:00
 
Fecha de Ingreso: febrero-2006
Mensajes: 446
Antigüedad: 18 años, 2 meses
Puntos: 3
cual puede ser el error que tengo el codigo?
gracias
  #5 (permalink)  
Antiguo 15/03/2006, 14:42
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
¡Je, je!

en vez de funcion hay que poner function...

function alMenosUno(a, b, c) {return (a != "" || b != "" || c != "");}

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #6 (permalink)  
Antiguo 15/03/2006, 15:31
 
Fecha de Ingreso: febrero-2006
Mensajes: 446
Antigüedad: 18 años, 2 meses
Puntos: 3
hola,funcion me equivoque en tipear aca,el error es que no coloque onSubmit en el form,lo habia puesto en el input ,no me resulta eso de colocar un mensaje de alert.

realize esto,pero no resulta.
Código:
<script>
function alMenosUno(a, b, c) {

if ((a != "") || (b != "") || (c != ""))
{
                    alert('debe ingresar en al menos uno');
                    }
}
</script>
Código:
<html>
<title>pagina</title>
<head>
<script>
function alMenosUno(a, b, c) {

alert('debe ingresar en al menos uno');
return (a != "" || b != "" || c != "")

}
</script>

</head>
<body>


<form name=formulario action=pagina.php method=post onsubmit="return alMenosUno(fichas_azules.value,fichas_verdes.value, fichas_rojas.value)">

<INPUT type="text" name="fichas_azules"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha" value="ingreso_ficha">

<INPUT type="text" name="fichas_rojas"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha1" value="ingreso_ficha1">

<INPUT type="text" name="fichas_verdes"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha2" value="ingreso_ficha2">
</form>
</body>
</html>
  #7 (permalink)  
Antiguo 15/03/2006, 16:04
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Pues, lo que importa es que devuelvas true al pasar la validación y false si no pasa, así que debes poner:

return loquesea; //true/false

Si quieres poner un alert al no validar, tendrías que hacer un paso intermedio:

function alMenosUno(a, b, c) {
vale = ((a != "") || (b != "") || (c != ""));
if (vale) alert('debe ingresar en al menos uno');
return vale;
}

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #8 (permalink)  
Antiguo 15/03/2006, 17:27
 
Fecha de Ingreso: febrero-2006
Mensajes: 446
Antigüedad: 18 años, 2 meses
Puntos: 3
caricatos gracias por la ayuda,ahora ya me funciona bien.
Código:
<html>
<title>pagina</title>
<head>
<script>
function alMenosUno(a, b, c)
{
vale = ((a != "") || (b != "") || (c != ""));
if (vale)
{
return true;
 }else
 {
         alert('debe ingresar en al menos uno');
         return vale;
         }
}
</script>
</head>
<body>


<form name=formulario action=pagina.php method=post onsubmit="return alMenosUno(fichas_azules.value,fichas_verdes.value, fichas_rojas.value)">
<INPUT type="text" name="fichas_azules"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha" value="ingreso_ficha">

<INPUT type="text" name="fichas_rojas"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha1" value="ingreso_ficha1">

<INPUT type="text" name="fichas_verdes"  size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<INPUT type="submit" name="ficha2" value="ingreso_ficha2">
</form>
</body>
</html>
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 05:35.