Solved

Not in list comma separated

Posted on 2014-02-11
8
322 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
  • 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now