Solved

Not in list comma separated

Posted on 2014-02-11
8
328 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

710 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