[eluser]Mackstar[/eluser]
Hi I managed to get it working, the JS is as follows
Code:
$(document).ready(function() {
$("#username").blur(function() {
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
//check the username exists or not from ajax
$.post("accounts/check_user_availability",{ username:$(this).val() } ,function(data) {
if(data=='no') {
$("#msgbox").fadeTo(200,0.1,function() { //start fading the messagebox
//add message and change the class of the box and start fading
$(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
});
}
else {
$("#msgbox").fadeTo(200,0.1,function() { //start fading the messagebox
//add message and change the class of the box and start fading
$(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
});
}
});
});
});
Also note that you had user_name being posted but the CI controller looking for username. So I have changed it in the js, which should now work.
FYI I have my other files as accounts.php
Code:
<?php
class Accounts extends Controller {
function Accounts()
{
parent::Controller();
//$this->load->model('usercontacts_model');
}
// --------------------------------------------------------------------
function index($message = '')
{
$data['extraHeadContent']= "[removed][removed]\n";
$data['extraHeadContent'].= "[removed][removed]\n";
$data['page_title'] = $this->lang->line('menu_accounts');
// $data['accounts'] = $this->usercontacts_model->get_admin_contacts();
$this->load->view('index', $data);
}
// --------------------------------------------------------------------
function check_user_availability()
{
$username = $this->input->post('username');
// Developed by Roshan Bhattarai
// Visit http://roshanbh.com.np for this script and more.
// This notice MUST stay intact for legal use
//this varible contains the array of existing users
$existing_users=array('ss','rr','ii');
//value got from the get metho
$user_name= $username;
//checking weather user exists or not in $existing_users array
if (in_array($user_name, $existing_users))
{
//user name is not availble
echo "no";
}
else
{
//user name is available
echo "yes";
}
}
}
and views/index.php as
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
[removed][removed]
[removed][removed]
</head>
<body>
<form>
User Name :
<input name="username" type="text" id="username" value="" maxlength="15" />
<span id="msgbox" style="display:none"></span>
<div id="msgbox"></div>
</form>
</body>
</html>
This seemed to work fine...
Cheers
Richard