Hi,
I am using following code to validate forms fields as well as name availability using jQuery and Ajax.
However, I need to disable form submission if the product name isn't available.
Please help ASAP
The code is as follows:
$(document).ready(function(){
$("#frmFamily").validate();
$("#fmlyName").change(function() {
var usr = $("#fmlyName").val();
if(usr.length >= 4)
{
$("#status").html('<img src="../../images/loader.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "POST",
url: "checkavailability.php",
data: "fmlyName="+ usr,
success: function(msg){
$("#status").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
// $("#fmlyName").removeClass('object_error'); // if necessary
//$("#fmlyName").addClass("object_ok");
$(this).html(' <img src="../../images/tick.gif" align="absmiddle">');
}
else
{
//$("#fmlyName").removeClass('object_ok'); // if necessary
$("#fmlyName").addClass("object_error");
$(this).html(msg);
}
});
}
});
}
else
{
$("#status").html('<font color="red">' +
'The Family name should have at least <strong>4</strong> characters.</font>');
$("#fmlyName").removeClass('object_ok'); // if necessary
$("#fmlyName").addClass("object_error");
}
});
});