Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

Not in list comma separated

I have a piece of code I'd like to comment out a bunch of zip codes that are comma delimited.  Right now I'm doing it in ranges with the below code, but would rather do it with comma delimited list of what they should not be IN.

$(function() {
$("#shipping_postcode").change(function(){
if($(this).val()>="30401" && $(this).val()<"30402" || $(this).val()>="30410" && $(this).val()<"30430" || $(this).val()>="30434" && $(this).val()<"30440" || $(this).val()>="30441" && $(this).val()<"30444" || $(this).val()>="30445" && $(this).val()<"30462" || $(this).val()>="30464" && $(this).val()<"30465" || $(this).val()>="30467" && $(this).val()<"30468" || $(this).val()>="30470" && $(this).val()<"30478" || $(this).val()>="31501" && $(this).val()<"" || $(this).val()>="50800" && $(this).val()<"50900"  || $(this).val()>="51000" && $(this).val()<"51700" || $(this).val()>="56000" && $(this).val()<"60100" || $(this).val()>="64000" && $(this).val()<"65100" || $(this).val()>="65300" && $(this).val()<"65500" || $(this).val()>="65600"){
     $("[for=shipping_method_fedexfedex_ground]").hide()
     $("#shipping_method_fedexfedex_ground").hide()
	 $("#shipping_method_fedexfedex_2_day").prop("checked", true)
} 
})
$("#shipping_postcode").change()
}) 

Open in new window

0
Nathan Riley
Asked:
Nathan Riley
  • 4
  • 4
3 Solutions
 
Nathan RileyFounder/CTOAuthor Commented:
Something like

if($this).val() in (123,521,648,3512)

Open in new window

0
 
leakim971PluritechnicianCommented:
Check this :
$(function() {
	var isAllowed = function(postcode) {
		var list = "30399,30400,30403,30404".split(","); // add here all not allowed postcode
		return $.inArray(postcode, list)<0;
	};
	$("#shipping_postcode").change(function(){
		var currPostCode = $(this).val();
		if( isAllowed(currPostCode) ){
			$("[for=shipping_method_fedexfedex_ground]").hide()
			$("#shipping_method_fedexfedex_ground").hide()
			$("#shipping_method_fedexfedex_2_day").prop("checked", true)
		}
	}).change();
});

Open in new window

0
 
Nathan RileyFounder/CTOAuthor Commented:
Appears to have the opposite effect.  I need the zips in the var list to do the opposite of what you have above.  do I put var isNotAllolwed?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
leakim971PluritechnicianCommented:
so replace line 4 by :
return $.inArray(postcode, list)>=0;

Open in new window

0
 
Nathan RileyFounder/CTOAuthor Commented:
Lastly I need to add if it's greater than 72587 it should also not be allowed to this code.
0
 
leakim971PluritechnicianCommented:
mix with your old code
0
 
Nathan RileyFounder/CTOAuthor Commented:
Is this correct?
$(function() {
	var isAllowed = function(postcode) {
		var list = "30401,71860,71861,71862,71864,71865,71866,72515,72517,72519,72528,72531,72533,72537,72538,72540,72544,72555,72556,72560,72565,72566,72567,72576,72578,72583,72585,".split(","); // add here all not allowed postcode
		return $.inArray(postcode, list)>=0;
	};
	$("#shipping_postcode").change(function(){
		var currPostCode = $(this).val();
		if( isAllowed(currPostCode) ){
			$("[for=shipping_method_fedexfedex_ground]").hide()
			$("#shipping_method_fedexfedex_ground").hide()
			$("#shipping_method_fedexfedex_2_day").prop("checked", true)
		}
		if($(this).val()>"72587") {
			$("[for=shipping_method_fedexfedex_ground]").hide()
			$("#shipping_method_fedexfedex_ground").hide()
			$("#shipping_method_fedexfedex_2_day").prop("checked", true)
		}
	}).change();
});

Open in new window

0
 
leakim971PluritechnicianCommented:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators
if( isAllowed(currPostCode) || (currPostCode > "72587") ) {
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now