How do I pass in an element's ID and a string to my function using on()?

The OnChangeListener has to take in the element’s ID that fires it and also must pass in a string (that will be hard-coded in). This isn’t working as I’ve learned that e is actually the event, not the select element. However, I don’t know how to retrieve the ID this way. This script is supposed to attach this event handler to all select elements that meet the selector’s criteria.

$(document).on('change', '[data-controltype=dropdown]', function (e) {
    OnChangeListener($(e).attr('id'), 'Dashboard.aspx/GetFilterDataCallBack');
});

I also tried this:

$(document).on('change', {senderId:$(this).attr('id'), callBack:'Dashboard.aspx/GetFilterDataCallBack' }, '[data-controltype=dropdown]', OnChangeListener});

That doesn’t appear to be working either.

Edit: this is in a <script> tag in my page.

Thanks in advance.

16 thoughts on “How do I pass in an element's ID and a string to my function using on()?”

Leave a Comment