steveosoule
11/25/2014 - 6:25 PM

Miva - Show/Hide "Other State"

Miva - Show/Hide "Other State"

// Hide the Shipping "Other State / Province" row
	if( $('#ShipStateSelect').length > 0 ){

		if( $('#ShipState').val() > 0 ){
			// Do Nothing
		} else if( $('#ShipStateSelect').val() === '' && $('#ShipState').val() === '' ){
			$('#ShipStateSelect').val( $($('#ShipStateSelect option')[1]).val() );
			$('#ShipState_Row').hide();
		} else{
			$('#ShipState_Row').hide();
		}

		$('#ShipStateSelect').change(function(){
			if( $(this).val() === '' ){
				$('#ShipState_Row').slideDown();
				if($('#ShipCountry').val() === 'US'){
					$('#ShipCountry').val('');
				}
			} else {
				$('#ShipState_Row').slideUp();

				if($('#ShipCountry').val() !== 'US'){
					$('#ShipCountry').val('US');
				}
			}
		});
	}

// Hide the Billing "Other State / Province" row
	if( $('#BillStateSelect').length > 0 ){

		if( $('#BillState').val().length > 0 ){
			// Do Nothing
		}
		else if( $('#BillStateSelect').val() === '' && $('#BillState').val() === '' ){
			$('#BillStateSelect').val( $($('#BillStateSelect option')[1]).val() );
			$('#BillState_Row').slideUp();
		} else{
			$('#BillState_Row').slideUp();
		}

		$('#BillStateSelect').change(function(){
			if($(this).val() === ''){
				$('#BillState_Row').slideDown();
				if($('#BillCountry').val() === 'US'){
					$('#BillCountry').val('');
				}
			} else {
				$('#BillState_Row').slideUp();

				if($('#BillCountry').val() !== 'US'){
					$('#BillCountry').val('US');
				}
			}
		});
	}

// Change the Billing to "Other State / Province" if the country is not US
	if( $('#BillCountry').find('option').length > 0 ){
		$('#BillCountry').change(function(){
			if($(this).val() !== 'US' && $('#BillStateSelect').val() !== ''){
				$('#BillStateSelect').val('').trigger('change');
			} else {
				$('#BillStateSelect').val( $($('#BillStateSelect').find('option')[1]).val() ).trigger('change');
			}
		});
	}

// Change the Shiping to "Other State / Province" if the country is not US
	if( $('#ShipCountry').find('option').length > 0 ){
		$('#ShipCountry').change(function(){
			if($(this).val() !== 'US' && $('#ShipStateSelect').val() !== ''){
				$('#ShipStateSelect').val('').trigger('change');
			} else {
				$('#ShipStateSelect').val( $($('#ShipStateSelect').find('option')[1]).val() ).trigger('change');
			}
		});
	}