javascript array to detect postcode
Posted: Wed Dec 01, 2010 4:35 am
I've got a site with a shopping cart and I need to put in on it a bit of JS script so that if the user puts in any postcode starting with a specific postcode region they will get flagged by an alert box and given an email / phone number to contact the site instead.
However I'm having a bit of trouble with the function as theres a LOT of post codes to add in. Around 100 I would guess.
So I started my function and tested it, then I wanted to add in an Array to hold all of the postcodes.
How would I alter:
[text]function doValidation() {
var b = true;
var p = document.getElementById('iPostcode');
var postcode = p.value.substring(0,3).toUpperCase()
if (postcode == 'IV3') {
b = false;
alert('We cannot accept your Postcode ' + postcode);
}
return b;
}[/text]
to check verse the entire Array?
Regards,
Aravona
However I'm having a bit of trouble with the function as theres a LOT of post codes to add in. Around 100 I would guess.
So I started my function and tested it, then I wanted to add in an Array to hold all of the postcodes.
How would I alter:
[text]function doValidation() {
var b = true;
var p = document.getElementById('iPostcode');
var postcode = p.value.substring(0,3).toUpperCase()
if (postcode == 'IV3') {
b = false;
alert('We cannot accept your Postcode ' + postcode);
}
return b;
}[/text]
to check verse the entire Array?
Regards,
Aravona