www.webdeveloper.com
Results 1 to 6 of 6

Thread: Compare values and redirect to an url

Hybrid View

  1. #1
    Join Date
    Dec 2010
    Posts
    6

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

  2. #2
    Join Date
    Dec 2010
    Posts
    63
    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.

    Cheers,
    Nick

  3. #3
    Join Date
    Dec 2010
    Posts
    6
    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

  4. #4
    Join Date
    Dec 2010
    Posts
    63

    Quick Fix

    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>

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

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

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



Recent Articles