1

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

5

Try below code:

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

HTH

Pradeep

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

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, privacy policy and cookie policy

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