Fiz isso aqui:
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest() {
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
//xmlHttp.open("get", "teste2.php", true);
xmlHttp.open("get", "teste2.php?login=" + document.getElementById('login').value, true);
// xmlHttp.send("login=" + document.getElementById("login") + "&endereco=" + document.getElementById("endereco"));
xmlHttp.send(null);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("resultado").innerHTML = xmlHttp.responseText;
}
}
}
</script>
<form action="#" name="formulario">
<input type="text" name="login" id="login" class="form"><a href="#" onclick="startRequest();">Verificar disponibilidade</a>
</form>
<div id="resultado"></div>
e na pagina teste2.php
<?php
include "conexao.php";
$login = $_REQUEST['login'];
if ( $login <> ""){
//Codigo para verificar se existe o login cadastrado
$sql = mysql_query("SELECT id FROM tabela WHERE nome='$login'");
$contar = mysql_num_rows($sql);
if($contar > 0) { $erro = "2"; } else { $erro = "3";}
} else {
$erro = "1";
}
if ($erro == "1") { $msg="Login nao informado"; }
if ($erro == "2") { $msg="Login ja cadastrado"; }
if ($erro == "3") { $msg="Login Disponivel"; }
echo $msg;
?>
O codigo está funcionando corretamente, porém eu queria que não fosse necessário o usúario clicar no botão "verificar disponibilidade"
Queri fazer qeu conforme ele fosse digitando já aparecece a resposta...
alguém sabe como posso fazer ?