How to disable form submit if the username is not available
- by Rajasekar
I have checked the user name availability. The problem is, even if the username is not available, the form is posting.
Edited Code:
<SCRIPT type="text/javascript">
$(document).ready(function(){
$("#emailch").change(function() {
var usr = $("#emailch").val();
if(usr.length >= 3)
{
$("#status").html('<img src="images/loader.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "POST",
url: "includes/check.php",
data: "username="+ usr,
success: function(msg){
$("#status").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
$("#username").removeClass('object_error'); // if necessary
$("#username").addClass("object_ok");
$(this).html(' <img src="images/tick.gif" align="absmiddle">');
}
else
{
$("#username").removeClass('object_ok'); // if necessary
$("#username").addClass("object_error");
$(this).html(msg);
}
});
}
});
}
else
{
$("#status").html('<font color="red">The username should have at least <strong>3</strong> characters.</font>');
$("#username").removeClass('object_ok'); // if necessary
$("#username").addClass("object_error");
}
});
});
</SCRIPT>
What I want is that, the form should not be posted if the user name is not available. I have tried by using return false; in IF CONDITION but it fails. Please suggest any alternate method. Any help will be appreciated.