viernes, 11 de diciembre de 2009

jQuery validar usuario existente en tiempo real

$("#nespacio").keyup(function(){
var max = 2;
// alert(e.keyCode);
if($("#nespacio").val().length>max)
{
var nick = $("#nespacio").val();
// alert("nick: " + nick);
var html = $.ajax({
// url: "ajax_existe_user.php?user_nick="+ nick,
type: "GET",
url: "php_clases/ajax_existe_user.php",
data: "user_nick=" + nick,
async: false
}).responseText;


//alert("asd: " + html);
if(html == "1")
{
//$("#nombre").val("User No Valido");
$("#img_valido").attr("src","images/cross.png");
$("#status").css("color","red");
$("#status").text("Usuario en uso");
}
else
{
//$("#nombre").val("User Valido");
$("#img_valido").attr("src","images/tick.png");
$("#status").css("color","green");
$("#status").text("OK");
}


//
//$("#nespacio").val($("#nespacio").val().substr(0, max));
//alert("Number of caracters max allowed is: "+ max);
}
else
{
//$("#nombre").val("");
$("#img_valido").attr("src","images/cross.png");
$("#status").text("");
}

});

2 comentarios: