validar 3 submit+javascript

shadow sonic

Lanero Reconocido
16 Ene 2004
225
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

este es el codigo que tengo,pero no me resulta,cual puede ser el error?
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>
 
creo que debes de especificar bien el objeto al cual le pides el valor...
por ejemplo:

Código:
<script>

funcion validar() {

var a = document.formulario.fichas_azules.value;
var b = document.formulario.fichas_verdes.value;
var c = document.formulario.fichas_rojas.value;

return (a != "" || b != "" || c != "");

}

</script>
 
hola,primero me equivoque en funcion ya que es function,y el otro error es que no coloque onSubmit en el form,lo habia puesto en el input ,Pero ahora no me resulta eso de colocar un mensaje de alert.

realize esto,pero no resulta,con el alert,pero no me resulta,como puedp arreglarlo.
gracias


Código:
<script>
function alMenosUno(a, b, c) {

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

}
</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>
 
Listo pelao...

aquí esta lo que quieres, pues al menos lo que te entendi...

<html>
<title>pagina</title>
<head>

<script>
function alMenosUno(formulario) {
if(formulario.fichas_azules.value == "" &&
formulario.fichas_rojas.value == "" &&
formulario.fichas_verdes.value == ""){
alert('debe ingresar en al menos uno');
return false;
}
else
return true;
}

function acceptNumNumero(evento){
var key = (window.Event)? evento.which : evento.keyCode;
if((key>=48 && key<=57) ||
(key==8))
return true;
else
return false;
}
</script>

</head>
<body>
<form name=formulario action=pagina.php method=post onsubmit="return alMenosUno(this)">

<input type="text" name="fichas_azules" size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<input type="submit" name="ficha0" value="ingreso_ficha0"><br>

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

<input type="text" name="fichas_verdes" size="5" maxlength="6"
onKeyPress="return acceptNumNumero(event)">&nbsp;
<input type="submit" name="ficha2" value="ingreso_ficha2"><br>

</form>
</body>
</html>

primero que todo te hace falta un método llamado "acceptNumNumero", según el nombre lo hice, espero que sea el que tenias en mente.

segundo te sugiero que te acostumbres a tabular el código fuente, no lo tabule en este caso para que lo entendieras mejor...

espero te sirva, hablamos mi vale... :p
 

Los últimos temas