Using ajax in Drupal 6 for cheking field without username_check. module or ajax.module

Relia's picture

Hello I'm dummy in Drupal!

I found a module which implement the function in AJAX that i want, but it only works in Drupal 5.X. I Prefer use it than username_check.module

What should i change in it, for working good???

this module contains 2 archives:


function demo_user_form_alter($form_id, &$form) {
drupal_add_js($module_path ."/demo_user.js");
if ($form_id == 'user_register') {
$username_verify_result = (div) class="reg_form_username" id="username_verify" style="display:none;")
(img src="'.base_path().drupal_get_path('module','demo_user').'/progress.gif" /)
Validating your username...
$username_status = '(div class="reg_form_username" id="username_status" style="display:none;")(/div)';
$form['name']['#suffix'] = $username_verify_result.$username_status;
$form['name']['#attributes'] = array('onblur' => 'usernameCheck(this)'); //added the call to our JS function

* Implemetation of hook_menu()
function demo_user_menu($may_cache){
$items = array();
if (!$may_cache) {
$items[] = array(
'path' => 'user/usernamecheck',
'title' => 'username check',
'callback' => 'demo_user_username_check',
'callback arguments' => array($_GET['username']),
'access' => true,
'type' => MENU_CALLBACK,
return $items;

* ajax user name check.
* Checks for the availability of a given username.
* @author Domenic Santangelo
* @param string $username The desired username
* @return string HTML-ified result of the check.
function demo_user_username_check($username) {
$result = db_result(db_query("SELECT name FROM {users} WHERE name = '%s'", $username));
if($result) {
$icon = "error.png";
$msg = " It looks like this username is already in use. Do you want to ". l('retrieve your password?','/user/password');
else {
$icon = "ok.png";
$msg = " The username is avaliable.";

//If we are working in our local site, a sleep effect could be necessary
echo "{$msg}";

and demo_user.js

function usernameCheck(obj) {
//Spinner shows while the ajax call does its thing

//Callback function that inserts the result of the username check in the div we set up in Step 1
function domCallback(msg) {

//Actually perform the call
type: "GET",
url: '/user/usernamecheck',
data: "username="+obj.value,
success: function(msg){