I use ajax to check if the user name is registered or not , here in this case i dont want to submit the form when the ajax result is false (ie,if username exists).
$(document).ready(function(){
$('#name').change(function(){
var name = $('#name').val();
if(name != '')
{
$.ajax({
url:"<?php echo site_url().'/login_controller/check_name_avalibility' ?>",
method:"POST",
data:{name:name},
success:function(data){
$('#name_result').html(data);
}
});
}
}); });