Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Not in list comma separated

Posted on 2014-02-11
8
Medium Priority
?
331 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:Nathan Riley
[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 12

Author Comment

by:Nathan Riley
ID: 39851308
Something like

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

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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 12

Author Comment

by:Nathan Riley
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
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

 
LVL 82

Assisted Solution

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

Open in new window

0
 
LVL 12

Author Comment

by:Nathan Riley
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 12

Author Comment

by:Nathan Riley
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 2000 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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

722 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