Adventures in Javascript: The mighty search by postal code

Filed under: Javascript — Tags: — Eike @ January 6, 2008 7:35 pm

I’m currently suffering from a cold (yes, again), and I’m not fit to do anything useful. But at least I can share a gem of client side programming I found in a friends website when he asked me to have a look at the site – he wasn’t quite satisfied with the results his contractor had delivered.

The site supposedly allows you to search for a shop by postal code. I was somewhat amazed: a search by postal code seemed somewhat excessive given that the company has only 15 shops in all of germany. I was even more suprised that the search field would not accept partial input – with this kind of search you would usually enter “1″ (instead of a full five-figure zip code) to find all matches in in Berlin and Brandenburg, I got an error message instead. When finally it turned out that the search returned always the same result (a list of all fifteen shops) no matter what I went looking for the code behind that “feature”. I found the following snippet of Javascript:

function plzSuche(id, url) {

 if(document.getElementById(id).value.length<5
 || isNaN(document.getElementById(id).value)){

  document.getElementById(id).style.color='red';

  alert("Die Postleitzahl ist fehlerhaft");

 } else {

  top.location.href=url;

 }

}

In case you don’t speak javascript: this function checks if the value of an input field is numeric and has at least five digits (hint: while a german postal code is always a number with five digits not every number with at least five digits is a valid german postal code). If the value is too short or not a number the function returns an error message. It is not clear what is the purpose of that, since all the function does is to redirect the user to an url that is passed to the function as parameter and is in no way computed from or even connected to the user input. So this is not only useless, since it expects a valid input for the ever same result it’s quite annoying.

I’m not the worlds greatest developer and have probably no business to lecture others on what they should do or not do. But anybody who comes up with bogus code like that and actually charges his client money is a fraud and should consider to pursue some other career than web programming (allegedly used car salesmen are allowed to get away with stuff like that).

    No Comments »

    No comments yet.

    RSS feed for comments on this post. TrackBack URL

    Leave a comment