country-region-selector
country-region-selector copied to clipboard
Presetting data attribute via jquery
Hello.
Thanks for this fantastic control!
Is there a way I can set the selected country and/or region via jquery?
I have an order form with billing and shipping and would like to provide the user with a checkbox to copy billing as shipping details.
So far I have not been successful with getting any of this to work.
Example (hard-coded/watered down for ease of explanation): $("#BillingCountry").attr('data-default-value', 'United States'); $("#BillingCountry").attr('default-value', 'United States'); $("#BillingCountry").attr('defaultvalue', 'United States');
etc. etc.
Your "pre-filling" examples work just fine but I'm looking to populate the selection dynamically NOT in the markup prior to page load as my page does not do any server postback between sections.
Thanks!
Ian
If you want to copy values across, your best bet would be to use something like:
$("#BillingCountry").val($("#ShippingCountry").val());
assuming you have a similar name convention for shipping. You aren't updating the default, you're setting it to something new.
I would also like to know how to do this - I am not able to get the region field to set when using Canada as the country and then running $("#state-province").val('Ontario');
for instance