Can't get onchange () to work in woocommerce

I am trying to determine if the value in the billing country dropdown has changed in woocommerce checkout fields. If it changed, get the value of the country the user selected and then do something about it.

For this I am using jquery code like this:

    $('#billing_country').on('change',function() {
        alert(this.value);
        // do something like alerting users that the book can not be shipped to the selected country.
    });

      

Below is the HTML code I found on the woocommerce checkout form page.

    <select id="billing_country" class="country_to_state country_select " name="billing_country" tabindex="-1" title="Country *" style="display: none;">
    <option value="">Select a countryโ€ฆ</option>
    <option value="AX">ร…land Islands</option>
    <option value="AF">Afghanistan</option>
    <option value="AL">Albania</option> 
    ...

      

The problem with the above code is that when I select another country from the dropdown, nothing happens at all.

Thank you in advance

+3


source to share





All Articles