Foros del Web » Programando para Internet » Javascript »

valdiar 2 input on submit

Estas en el tema de valdiar 2 input on submit en el foro de Javascript en Foros del Web. Tengo el siguiente codigo para validar un solo input como puedo hacer validar otro input text con esto mismo? Código HTML: <html> <head> <meta http-equiv="Content-Type" ...
  #1 (permalink)  
Antiguo 21/01/2013, 10:30
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
valdiar 2 input on submit

Tengo el siguiente codigo para validar un solo input
como puedo hacer validar otro input text con esto mismo?


Código HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
<script type="text/javascript">
function compruebaCv(archivo) {
	if (!archivo) { 
		alert("Debes subir tu archivo")
		return false;
	}else{
		return true; 
	} 
} 
</script>
</head>

<body>

<form id="registracion" enctype="multipart/form-data" name="registracion" method="post" action="borrar.php" onsubmit="return compruebaCv(this.form.cv.value);">

</form>
</body>
</html> 
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #2 (permalink)  
Antiguo 21/01/2013, 14:47
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: valdiar 2 input on submit

simple, no retornes de una vez, usa una variable para el retorno y pasa la instancia del form, no de un solo elemento:

<form id="registracion" enctype="multipart/form-data" name="registracion" method="post" action="borrar.php" onsubmit="return compruebaCv(this);">

Código Javascript:
Ver original
  1. function compruebaCv(formulario) {
  2.     var retorno = true;
  3.     if (! formulario.elements['archivo'].value) {
  4.         alert("Debes subir tu archivo 1")
  5.         retorno = false;
  6.     }
  7.     if (! formulario.elements['archivo2'].value) {
  8.         alert("Debes subir tu archivo 2")
  9.         retorno = false;
  10.     }
  11.     return retorno; //si todo ha sido correcto, retornará true
  12. }
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...

Etiquetas: html, input, submit
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 22:54.