/    Sign up×
Community /Pin to ProfileBookmark

Compare values and redirect to an url

Hi, there

I,ve searched for a couple of hours and have seen an awful lot of webpages this day, still i can not find the answer to, i think, a quite simple question.
First of all, my scripting skills are quite poor. I’m very willing to learn and i am determined to get my question fixed. I am not asking for a complete script, just lokking for some handles and een kick in the right direction.

What’s my “problem”:
For my website, i want a kind of postal code check.
When someone fills in his postalcode and submitted this, he needs to be directed to another page, with information regarding the region that belongs to his postal code.

I have a wild guess how this should work, but please, correct me if i’m (probably very) wrong:

I will have to create a form, with only one field: postal code.
The “action”of that form has to point to a javascript.
That script compares the value of the filled in postalcode to some document (txt, xml ??) or database.
If the two value match, the user will be directed to another url.

Is there someone who can gives me a push in the right direction ?

Thanks in advance,
Klaas
The Hague, Netherlands

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JavaScriptNickDec 21.2010 — You seem to be on the correct [I]logic[/I] path. What I would do (somebody else's opinion would probably differ) is google for a PHP zip code script. You would likely get some sql code to upload to a MySQL database and a corresponding PHP script. The PHP script itself wouldn't be too complex but that data in the db would be enormous. Worth outsourcing in my opinion.

Cheers,

Nick
Copy linkTweet thisAlerts:
@MesjoggahauthorDec 21.2010 — Hi, Nick

Thank you for your reply !

The db will not be that big.

There are off course lots of postal codes in the Netherlands, but thay are in devided in roughly 100 area's. And that's all i need.

So the script must check if the postal code is for example bigger than 1000 and smaller than 1501. If so, the user must be directed to another url.

The "zip code" tip is a good one ! It's already night here, so i'll search for it tomorrow first in the morning.

Thanks !

Klaas
Copy linkTweet thisAlerts:
@JavaScriptNickDec 21.2010 — Ohhhhhhh, I see.... I thought you were looking for all zip codes across the globe. Hold please... ?
Copy linkTweet thisAlerts:
@JavaScriptNickDec 21.2010 — This would probably need some optimization. But should give you an idea.

[CODE]

<html>

<head>

<script type="text/javascript">

var $ = function(id) { return document.getElementById(id); }

var getCode = function() {
var zip = parseInt($("txtZip").value);
if (zip >= 999 && zip <= 1099) {
alert("Amsterdam");
window.location = 'http://www.google.com' // Change url
}

if (zip >= 1100 && zip <= 1199) {
alert("Amstelveen");
}
}

window.onload = function() {
$("btnSubmit").onclick = getCode;
}

</script>

</head>

<body>

<h3>Postal Code</h3>
<input type="text" id="txtZip">
<br />
<input type="button" id="btnSubmit" value="Submit">

</body>

</html>


[/CODE]
Copy linkTweet thisAlerts:
@MesjoggahauthorDec 22.2010 — Hi, Nick

Your push in the direction of PHP was a good one. I've found a script, that looked very promising and changed it a bit for my own purpose.

It contains still an error, but because of the nature of this forum (Javascript) i think i'll have to move to the PHP side, to get some advice !

Again,

Thanks for your effort !
×

Success!

Help @Mesjoggah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...