balkan7 Posted July 21, 2008 Share Posted July 21, 2008 i have created code for check username, but ajax nothing respond me code is: <script> function createRequestObject() { var req; if(window.XMLHttpRequest){ // Firefox, Safari, Opera... req = new XMLHttpRequest(); } else if(window.ActiveXObject) { // Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else { // There is an error creating the object, // just as an old browser is being used. alert('Problem creating the XMLHttpRequest object'); } return req; } var http = createRequestObject(); function useHttpResponseusername() { if (http.readyState == 4) { var textOut = http.responseText; var update = new Array(); document.getElementById('usercheck').innerHTML = textOut; if(textOut.indexOf('|' != -1)) { update = textOut.split('|'); document.getElementById(update[0]).innerHTML = update[1]; } } } function checkusername(username) { http.open('get', 'register.php?check=true&checkusername='+username+'&rand='+Math.random(), true); http.onreadystatechange = useHttpResponseusername; http.send(null); } </script> php code: <?php if(isset($_GET['check'])) { echo "<style type='text/css'> .quoteerror { color : #FFFFFF; background-color : #FF0000; border : 1px solid #C11B17; } </style>"; if(isset($_GET['checkusername'])) { $username = stripinput(trim(eregi_replace(" +", " ", $_GET['checkusername']))); if (!preg_match("/^[-0-9A-Z_@\s]+$/i", $username)) echo "<div class='quoteerror'><center>".$locale['403']."</center></div>"; $result = dbquery("SELECT * FROM ".DB_USERS." WHERE user_name='$username'"); if (dbrows($result) != 0) { $ajax_responde = "checkusername|<img src='images/icon_ajax_false.gif' border='0'> <span style='color: #FF0000;'>This username has already been taken</span>"; } else { $ajax_responde = "checkusername|<img src='images/icon_ajax_true.gif' border='0'> <span style='color: #008000;'>This username is still available.</span>"; } die(); } } ?> and <input type='text' name='username' maxlength='30' class='textbox' style='width:200px;' onChange='checkusername(this.value)' /><div id='usercheck'></div> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.