| | |
username availability gmail-style (javascript+sql)
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
Hi all.
I am currently developing a CMS for a school project and I wanted to add the function to check, real-time, if a username is already taken. It should be a little bit like what happens when you register for a Gmail or Yahoo! account.
Basically, while the user inputs the desired username in a textbox, I want to make appear next to it a green or red sign (plus a small text) to display availability.
The registered usernames will be in a mysql table which I can query with a very basic SELECT statement.
It should work AS THE USER TYPES, so if he's entering "mrbrown" then it should try to query for every letter.
This will be my first AJAX implementation, so I am asking for a starting point and any suggestion you deem could help me.
Thanks!
I am currently developing a CMS for a school project and I wanted to add the function to check, real-time, if a username is already taken. It should be a little bit like what happens when you register for a Gmail or Yahoo! account.
Basically, while the user inputs the desired username in a textbox, I want to make appear next to it a green or red sign (plus a small text) to display availability.
The registered usernames will be in a mysql table which I can query with a very basic SELECT statement.
It should work AS THE USER TYPES, so if he's entering "mrbrown" then it should try to query for every letter.
This will be my first AJAX implementation, so I am asking for a starting point and any suggestion you deem could help me.
Thanks!
Th JavaScript code for this will be similar to: (You will need to modify this)
HTML for the username box:
And rpc.php
Note, the PHP code if not good, there is no checking for bad data so it is not secure, just an example
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript"> function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer") { ro = new ActiveXObject("Microsoft.XMLHTTP"); }else { ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject(); function sndReq(action) { if(action.length < 3) { if(action.length == 0) { document.getElementById('usernamecheck').innerHTML = "<br />"; return false; } document.getElementById('usernamecheck').innerHTML = "Username too short"; return false; }else { http.open('get', 'rpc.php?action='+action); http.onreadystatechange = handleResponse; http.send(null); } } function handleResponse() { if(http.readyState == 4) { var update = http.responseText; if(update!="This name is Avaliable!") { document.getElementById('usernamecheck').innerHTML = "This name is unavaliable, please try again"; }else { document.getElementById('usernamecheck').innerHTML = "<a href='Javascript:EnableDisable()'>"+update+" Click to change</a>"; } } } </script>
HTML for the username box:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<input type="text" name="un" onchange="sndReq(this.value)">
And rpc.php
php Syntax (Toggle Plain Text)
<? //connect to db first $user=mysql_query("SELECT * FROM user_table WHERE un = '".$_REQUEST['action']."'")or die(mysql_error()); $countrows=mysql_num_rows($user); if($countrows > 0) { echo "This name is Unavaliable"; } else { echo"This name is Avaliable!"; } ?>
Note, the PHP code if not good, there is no checking for bad data so it is not secure, just an example
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: I need a script or applet, to insert text into text fields in different websites.
- Next Thread: Where can i find the js files???
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp animate api automatically beta boarder box bug calendar captchaformproblem card checkbox child class column cookies createrange() css cursor dependent disablefirebug dom download dropdown editor element engine error events explorer ext file firehose flash form forms google gwt html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump math matrixcaptcha microsoft mimic mp3 mysql object offline onmouseoutdivproblem onreadystatechange parent passing pdf php player post problem progressbar rated rating regex runtime scroll search select session shopping size sql star stars stretch text textarea twitter validation w3c web website window windowofwords windowsxp wysiwyg xml xspf \n





