mercredi 26 août 2015

if block not working as expected in jQuery

Following jQuery function is being called from a View in an ASP.Net MVC3 project:

function ValidateRequestor() {
    var regex = /^[A-Za-z0-9]*$/;

    var frstNameval = $('[id*=FirstName]').val();
    if (!(/[a-z]/i.test(frstNameval))) {
        $('[id*=FirstName]').val("");
        $('[id*=FirstName]').focus();
        alert("Please specify a proper first name.");
        return false;
    }
    if (frstNameval == '') {
        alert("Please specify a first name.");
        return false;
    }
    var lstNameval = $('[id*=LastName]').val();
    if (!(/[a-z]/i.test(lstNameval))) {
        $('[id*=LastName]').val("");
        $('[id*=LastName]').focus();
        alert("Please specify a proper last name.");
        return false;
    }
    if (lstNameval == '') {
        alert("Please specify a last name.");
        return false;
    }

//    var Approvedval = $('#_SelectedGeography').val();
//    //debugger;
    if ($('#_SelectedGeography').val() == '') {
        alert("Please specify Approval Group.");
        return false;
    }
    debugger;
    if ($('#TextFAFM').length > 0) {
        if ($('#TextFAFM').val().length>0) {
            return true;
        }
        else if ($('#TextFAFM').val() == '') {
            alert("Please specify Financial Analyst.");
            return false;
        }        
    }
    else
        return true;
}

However the below block of code is not working as expected:

if ($('#TextFAFM').length > 0) {
            if ($('#TextFAFM').val().length>0) {
                return true;
            }
            else if ($('#TextFAFM').val() == '') {
                alert("Please specify Financial Analyst.");
                return false;
            }        
        }

The block which returns True is not getting executed. Please help.

Aucun commentaire:

Enregistrer un commentaire