jaimex8
2/17/2016 - 4:37 PM

Change province fields when country changes

Change province fields when country changes

		// ---- Change State/ Province ---- //
		var CAProv = {AB:"Alberta",BC:"British Columbia",MB:"Manitoba",NB:"New Brunswick",NL:"Newfoundland and Labrador",NT:"Northwest Territories",NS:"Nova Scotia",NU:"Nunavut",ON:"Ontario",PE:"Prince Edward Island",QC:"Quebec",SK:"Saskatchewan",YT:"Yukon"},
			shipcountrySelect = $('#ShipCountry'),
			billcountrySelect = $('#BillCountry'),
			sOtherStateRow = $('.ship-other-state'),
			bOtherStateRow = $('.bill-other-state'),
			sStateSelectRow = $('.ship-state-select'),
			bStateSelectRow = $('.bill-state-select')
			sOtherState = $('#l-ShipState'),
			sStateSelect = $('#ShipStateSelect'),
			bOtherState = $('#l-BillState'),
			bStateSelect = $('#BillStateSelect');

		function changeOptions () {
			// Shipping
		   if (shipcountrySelect.val() == 'US') {
		   	// UNITED STATES
		      sOtherStateRow.hide();
		      sStateSelectRow.show();
		      $('.ship-zip-row label').text('Zip Code');
		   } else if (shipcountrySelect.val() == 'CA') {
		   	// CANADA
   			   $('.ship-other-state input').replaceWith($('#ca-replace select#ShipState').clone());
   			   $('.ship-other-state label').text('Province').removeClass('required');
   			   $('.ship-other-state select').removeClass('required-field');
   			   $('.ship-zip-row label').text('Postal Code');
		        sOtherStateRow.show();
		        sStateSelectRow.hide();
		        sStateSelect.val('');
		   } else {
		   	// OTHER
		   	$('.ship-other-state select').replaceWith('<input type="text" name="ShipState" id="l-ShipState" value="" class="input-small-font medium-input-normal-font" />');
		   	$('.ship-other-state label').text('State').removeClass('required');
		   	$('.ship-other-state input').removeClass('required-field');
		   	$('.ship-zip-row label').text('Postal Code');
		   	sOtherStateRow.show();
		   	sStateSelectRow.hide();
		   	sStateSelect.val('');
		   }
		   // Billing
   		   if (billcountrySelect.val() == 'US') {
		   	// UNITED STATES
		      bOtherStateRow.hide();
		      bStateSelectRow.show();
		      $('.bill-zip-row label').text('Zip Code');
		   } else if (billcountrySelect.val() == 'CA') {
		   	// CANADA
   			   $('.bill-other-state input').replaceWith($('#ca-replace select#BillState').clone());
   			   $('.bill-other-state label').text('Province').removeClass('required');
   			   $('.bill-other-state select').removeClass('required-field');
   			   $('.bill-zip-row label').text('Postal Code');
		        bOtherStateRow.show();
		        bStateSelectRow.hide();
		        bStateSelect.val('');
		   } else {
		   	// OTHER
		   	$('.bill-other-state select').replaceWith('<input type="text" name="BillState" id="l-BillState" value="" class="input-small-font medium-input-normal-font">');
		   	$('.bill-other-state label').text('State').removeClass('required');
		   		$('.bill-other-state input').removeClass('required-field');
		   	$('.bill-zip-row label').text('Postal Code');
		   	bOtherStateRow.show();
		   	bStateSelectRow.hide();
		   	bStateSelect.val('');
		   }
		}
		changeOptions();
		$('#ShipCountry, #BillCountry').on('change', function () {
		   changeOptions();
		});