How can I listen in JavaScript to the event of a country value change on the country select field?

both #select2-drop-mask and #select2-drop are not available until the user clicks to open the select.

and the hidden select #country-5 is not firing the change event as its values are set programatically.

This question was asked here but has a wrong answer.

Thank you

2 Answers 2


Try below code:

  CRM.$(function($) {
    $('#billing_country_id-5').change(function () {
      var countryId = $(this).val();



  • Yes! thank you! oh I've been working on this for hours!
    – Elad
    Jan 29, 2018 at 10:18

In general, when you want to listen to an event on a select2 you place the listener on the original form element (which is either an <input> or a <select>). When inspecting the dom, you'll see it close to the select2 div, hidden because it has the select2-offscreen class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.