Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/08/2007, 23:36
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Re: ajax + js + submit

Sería algo así, sólo que en lugar de usar un array harías algo semejante pero consultando a la base de datos:
Código PHP:
<?php
if(isset($_GET['p']) && !empty($_GET['p'])){
$users=array('pepe','jose','pedro');
if(
in_array($_GET['p'],$users)){
echo 
'usuarioexiste=true;';
}else{
echo 
'usuarioexiste=false;';
}
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<script>
function rpc(url){
    oldsc=document.getElementById("old_sc");
       if(oldsc)
            document.getElementsByTagName('body')[0].removeChild(oldsc);
    sc=document.createElement('script');
    sc.id="old_sc";
    sc.src=url+'&'+Math.random();
    document.getElementsByTagName('body')[0].appendChild(sc);
}
function validar(){
if(document.forms[0].usuario.value.length<1){
alert('completar usuario');return false;
}
if(usuarioexiste){
alert('el usuario ya existe');return false;
}
if(document.forms[0].password.value.length<5){
alert('clave incorrecta');return false;
}

return true;
}
</script> 
</head>

<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return validar()">
user(pepe,jose y pedro existen):<br />
<input name="usuario" type="text" id="usuario" onblur="rpc('?p='+this.value)" />
  <br />
  <br />
  pass (m&iacute;nimo 5 caracteres):<br />
<input name="password" type="password" id="password" />
  <br />
  <br />
  <input type="submit" name="Submit" value="Enviar" />
</form>
</body>
</html>