Okay, as I posted before I needed a system that checked if a username has already been registered. I have found a code, but there is no go. For the AJAX part, I have this:
It's supposed to change the div, but it doesn't. I believe it gets the result from here, but I am not sure:
That file is called AJAX.php. If I go to that page, with the ?do and stuff then I get a true result, but it's not showing up on the first bit of code. I don't really understand Javascript that much, so I am trying to learn. Any support will be helpful!
Thank you.
| Code: |
| <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> |
It's supposed to change the div, but it doesn't. I believe it gets the result from here, but I am not sure:
| Code: |
| <?php
include("members/config.php"); $do = $_GET['do']; switch($do) { case 'check_username_exists': if(get_magic_quotes_gpc()) { $username = $_GET['username']; }else{ $username = addslashes($_GET['username']); } $count = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`='".$username."'")); header('Content-Type: text/xml'); header('Pragma: no-cache'); echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<result>'; if($count > 0) { echo 'That username already exists, please select another one.'; }else{ echo 'That username is available.'; } echo '</result>'; break; default: echo 'Error, invalid action'; break; } ?> |
That file is called AJAX.php. If I go to that page, with the ?do and stuff then I get a true result, but it's not showing up on the first bit of code. I don't really understand Javascript that much, so I am trying to learn. Any support will be helpful!
Thank you.
