I am facing a challenge in adding the click event on a link.
$('#submitDomainName').live('click', function(){
fnCheckDomainNameExists();
var myRegEx = new RegExp(/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/);
userInputDomain = validateUserDomain($('#customDomainName').val());
if (!userInputDomain.match(myRegEx)) {
alert("Please enter a valid domain name");
return;
}
if(confirm('Are you sure to move to a custom domain')){
//alert(userCustomDomainNameUpdated);
$.post('saveCustomDomain.php',{userExistingDomainName:userExistingDomainName,userCustomDomainName:userCustomDomainNameUpdated},function(data){
$('#popUpContent').html('<div class="alertBoxContainer"><h2>You have Successfully Published your website on your Domain</h2><a style="color:#ffffff;" target="_blank" href="http://'+data+'">'+data+'</a><br class="clear" /></div>');
})
}
});
In the above click fucntion I want first the fnCheckDomainNameExists() to be executed and checked and then the callback to proceed.The function is below:
function fnCheckDomainNameExists(){
userInputDomain = validateUserDomain($('#customDomainName').val());
$.post('checkExistingDomain.php',{userInputDomain:userInputDomain},function(data){
//alert(data);
if(data=='false'){
alert('Domain name already in use.Please chose a different one');
return;
}
})
}
What happens is as I click the link instead of fnCheckDomainNameExists the callback funcion with confirm box "Are you sure to move to a custom domain appears.I want first to check if the domain is new and then execute the callback.
I also tried using it with if(!fnCheckDomainNameExists ())