Problem with .on('change.yii',...) and retrieving value

Hi all:

I have this code in a JS asset for a select element:




function contactedCaseInfo() {

    $("#contacted-cases_id").on("change.yii", function() {

        var casenum = $("#contacted-form-id").yiiActiveForm("find", "contacted-cases_id").value;

        alert("Case number is: " + casenum);

    });

}

contactedCaseInfo();



I can also do:




var casenum = $("contacted-cases_id").value;



with the same results.

Whenever the change is triggered I get either empty for a first time selection (doesn’t matter what I select) or else the value of the previous selection after the first one when I keep selecting. It looks like the .on() event is firing too fast to allow the value of the select option to settle. Any ideas on how to handle this? Thanks for the help.

Regards,

Nevermind, I solved it; instead of




 var casenum = $("#contacted-form-id").yiiActiveForm("find", "contacted-cases_id").value;



it was as easy as




var casenum = $(this).val();



Still don’t understand why yiiActiveForms(‘find’,…) didn’t work.

Cheers,