i have built a username check on a textfield that when the username already existed in the database there will be an alert
the javascript runs in onBlur of the textfield
everything works okay except the textfield check when the textfield is blank(onreadystagechange >>>> change from something to nothing)
Can anyone please help to fix this bug???? the code is as below:
Code:<script type="text/javascript"> var xmlHttp; function createXHR() { if (window.XMLHttpRequest) { xmlHttp= new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlHttp= new ActiveXObject("Microsoft.XMLHTTP"); } if (!xmlHttp) { alert('Your browser does not support XMLHTTP object'); return false; } } createXHR(); function sendUsername(n) { document.getElementById('alert_username').innerHTML='checking'; xmlHttp.onreadystatechange=catchUsername; xmlHttp.open('GET','reg.php?timeStamp='+new Date().getTime()+'&search='+n,true); xmlHttp.send(null); } function catchUsername() { if (xmlHttp.readyState==4) { if (xmlHttp.status==200) { var s=xmlHttp.responseText; if (s==true) { document.getElementById('check_username').innerHTML=''; document.getElementById('alert_username').innerHTML='username already been used'; } else { document.getElementById('alert_username').innerHTML=""; document.getElementById('check_username').innerHTML='<img src="../check.png">'; } } } } </script> <form> <input name="username" id="username" type="text" onBlur="sendUsername(this.value);" value="<?php echo stripslashes(htmlentities($_POST['username'])); ?>"/> <span id="check_username"></span> <div id="alert_username"></div> </form>
reg.php
just some php code to connect to the database and retrieve the data and check whether the value from the textfield exist already.
if yes, echo true, else echo false


(onreadystagechange >>>> change from something to nothing)
Reply With Quote
Bookmarks