Ver Mensaje Individual
  #10 (permalink)  
Antiguo 08/02/2013, 13:20
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: no me funciona return en javascript

Cita:
Iniciado por fandurc Ver Mensaje
me ejecuta envia siempre el form aunque falten datos y me ejecuta el php. Saludos
En casos asi vas a lo seguro
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6.  
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. function enviar(){
  10.    var username = document.getElementById("username").value;
  11.    var password = document.getElementById("password").value;
  12.    if ((username == "") || (password == "")) {        
  13.        alert("Debe ingresar su Nombre de Usuario y su Contraseña para acceder");
  14.        return false;        
  15.    }
  16. }
  17.  
  18. //]]>
  19. </head>
  20. <form action="ingreso.php" method="post" onsubmit="return enviar();">
  21. usuario <input type="text" name="username" id="username" value="" /><br />
  22. clave <input type="password" name="username" id="password" value="" /><br />
  23. <input type="submit" name="procesar" />
  24. </form>
  25. </body>
  26. </html>

Como tu mensaje afecta a los 2 errores, usas || (OR) y no && (AND)

Veo por ahi dando vueltas un trim(), supongo que en alguna parte dicha función esta definida, y el trim debés hacérlo a la s variables username y password antes del condicional

Si querés otra combinación, a experimentar un poco

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.