Hi,
I'm trying to to update the javascript code with: If the country selected not US or Canada, make Zip Code is not required. In Nopcommerce the Zip Code field is always required.
The javascript code basically fills the StateProvince dropdown select when an option is selected in the Country dropdown select.
Could you please help me to update the code?
Here is the javascript code inside _CreateOrUpdateAddress.cshtml:
<script type="text/javascript">
$(document).ready(function() {
$("#Address_CountryId").change(function() {
var selectedItem = $(this).val();
var ddlStates = $("#Address_StateProvinceId");
$.ajax({
cache: false,
type: "GET",
url: "/Admin/Country/GetStatesByCountryId",
data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
success: function(data) {
ddlStates.html('');
$.each(data, function(id, option) {
ddlStates.append($('<option></option>').val(option.id).html(option.name));
});
},
error: function(xhr, ajaxOptions, thrownError) {
alert('Failed to retrieve states.');
}
});
});
});
</script>
<input id="Address_ZipPostalCodeEnabled" type="hidden" value="True" name="Address.ZipPostalCodeEnabled" data-val-required="'Zip Postal Code Enabled' must not be empty." data-val="true">
<input id="Address_ZipPostalCodeRequired" type="hidden" value="True" name="Address.ZipPostalCodeRequired" data-val-required="'Zip Postal Code Required' must not be empty." data-val="true">
Thanks!