Results 1 to 6 of 6

Thread: Compare values and redirect to an url

  1. #1
    Join Date
    Dec 2010

    Post 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,
    The Hague, Netherlands

  2. #2
    Join Date
    Dec 2010
    You seem to be on the correct logic 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.


  3. #3
    Join Date
    Dec 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 !

  4. #4
    Join Date
    Dec 2010
    Ohhhhhhh, I see.... I thought you were looking for all zip codes across the globe. Hold please...

  5. #5
    Join Date
    Dec 2010

    Quick Fix

    This would probably need some optimization. But should give you an idea.

    <script type="text/javascript">
    var $ = function(id) { return document.getElementById(id); }
    var getCode = function() {
    	var zip = parseInt($("txtZip").value);
    	if (zip >= 999 && zip <= 1099) {
    	window.location = 'http://www.google.com' // Change url
    	if (zip >= 1100 && zip <= 1199) {
    window.onload = function() {
    $("btnSubmit").onclick = getCode;
    <h3>Postal Code</h3>
    <input type="text" id="txtZip">
    <br />
    <input type="button" id="btnSubmit" value="Submit">

  6. #6
    Join Date
    Dec 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 !

    Thanks for your effort !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center