Solved

Not in list comma separated

Posted on 2014-02-11
8
327 Views
Last Modified: 2014-02-11
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
Comment
Question by:N R
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 11

Author Comment

by:N R
ID: 39851308
Something like

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

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39851314
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
 
LVL 11

Author Comment

by:N R
ID: 39851743
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
Independent Software Vendors: 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!

 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 39851755
so replace line 4 by :
return $.inArray(postcode, list)>=0;

Open in new window

0
 
LVL 11

Author Comment

by:N R
ID: 39851816
Lastly I need to add if it's greater than 72587 it should also not be allowed to this code.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39851824
mix with your old code
0
 
LVL 11

Author Comment

by:N R
ID: 39851831
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
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 39851838
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators
if( isAllowed(currPostCode) || (currPostCode > "72587") ) {
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question