Antarr Byrd
Antarr Byrd

Reputation: 26061

Jquery function not being executed

I'm trying to execute this function when a select list's (LevelId0) value change but its not being executed. Tried this inside $(document).ready() and outside of it. hasFullAccess is a local boolean variable in the window.

$("#LevelId0").change(function() {
    if (hasFullAccess) {
        alert("oy");
    }
    else {
        alert("oi");
        // var currentYear = (new Date).getFullYear();
        // $(".bound").val("01/01/" + (currentYear + 1));
        //$(".EffectiveDateClass").val("01/01/"+(currentYear +1));
    }
});​

SOLUTION

@if (!hasFullAccess)
    {
        <text>$(document).on('change', "#LevelId0, #CLevelId1", function() {
            var currentYear = (new Date).getFullYear();
            $("#LevelId1, #LevelId0").val($(this).val());
            $("#EffectiveDate0, #EffectiveDate1,.EffectiveDateClass").val("01/01/" + (currentYear + 1));
            });
        </text>
        }

Upvotes: 0

Views: 157

Answers (1)

Mark Schultheiss
Mark Schultheiss

Reputation: 34158

jQuery(document).ready(function() {
    $(document).on('change', "#LevelId0", function() {
        if (hasFullAccess) {
            alert("oy");
        } else {
            alert("oi"); // var currentYear = (new Date).getFullYear();    
            // $(".bound").val("01/01/" + (currentYear + 1));     
            //$(".EffectiveDateClass").val("01/01/"+(currentYear +1)); 
        }
    });
});

what you really want perhaps:

jQuery(document).ready(function() {
    $(document).on('change', "#LevelId0, #LevelId1", function() {
        updateValues();
    });
});

What does this alert in the $(document).ready(:

alert(hasFullAccess);

EDIT: ALTERED FUNCTION:

jQuery(document).ready(function() {
    $(document).on('change', "#LevelId0", function() {
        if (typeof hasFullAccess === "undefined") {
            alert("oy");
        } else {
            alert("oi");
        }
    });
});

Upvotes: 1

Related Questions