country-region-selector icon indicating copy to clipboard operation
country-region-selector copied to clipboard

Presetting data attribute via jquery

Open ianscarroll opened this issue 9 years ago • 2 comments

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

ianscarroll avatar Jan 29 '16 22:01 ianscarroll

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.

ellenhutchings avatar Feb 09 '16 01:02 ellenhutchings

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

Alex-Mann avatar Sep 06 '16 20:09 Alex-Mann