Jump to content

[SOLVED] check user exists in database


vinpkl

Recommended Posts

hi all

 

i m using the below script to check live check user in database.

 

This script works fine for me. I just need to have the same effect when the user enters the username and his cursor is still in the input box.

 

At present to show mesage whether the username exists or not the customer has to enter the username and then put the cursor in the next input field.

 

<script type="text/javascript"> 
function toggle_username(userid) { 
    if (window.XMLHttpRequest) { 
        http = new XMLHttpRequest(); 
    } else if (window.ActiveXObject) { 
        http = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    handle = document.getElementById(userid); 
    var url = 'ajax.php?'; 
    if(handle.value.length > 0) { 
        var fullurl = url + 'do=check_username_exists&username=' + encodeURIComponent(handle.value); 
        http.open("GET", fullurl, true); 
        http.send(null); 
        http.onreadystatechange = statechange_username; 
    }else{ 
        document.getElementById('username_exists').innerHTML = ''; 
    } 
} 

function statechange_username() { 
    if (http.readyState == 4) { 
        var xmlObj = http.responseXML; 
        var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data; 
        document.getElementById('username_exists').innerHTML = html; 
    } 
} 
</script> 
<input id="username" type="text" name="username" onchange="toggle_username('username')" /><br /> 
<div id="username_exists" style="font-size: 11px;font-weight: bold;color:#FF3300"> </div> 

 

vineet

Link to comment
https://forums.phpfreaks.com/topic/138962-solved-check-user-exists-in-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.