Home » Topics » 

Javascript

Automatic geolocation and SQL

Zdenek Machek | 16 November 2010

Geolocation previewRecently we launched a website and platform for iGo Gift Vouchers. One of the screens shows an interactive list of the shops where vouchers can be used. The classic interface design pattern for this is to ask users to provide a postcode, or the name of a city or town, and then display the shops in that area on a map.

As usual, we decided to try something new and improve a little on the traditional functionality. We wanted to automatically detect where the user is right now, so we can display shops in their area as soon as they arrive on the page, without them having to enter any information. You can see how it works at www.igogiftvouchers.co.uk/myigo - when your browser asks if you would like to share your location with the page, just click the option to accept.

So why Geolocation and SQL? The first part of this task, identifying where the user is, is handled on the client side usining JavaScript. But SQL comes in as the best and fastest tool for the second part of the task: identifying which shops are nearest and should be displayed on the map.

Read more 3 comments


apache_prettify

Nick Nettleton | 24 April 2009

apache_prettify adds code colouring and line numbers to Apache configuration code - the stuff you write in httpd.conf and .htaccess. Most useful if you are publishing this sort of code in your blog.

  • Written in JavaScript - works in the browser
  • Dead easy to use
  • Compatible with all JS libraries - jQuery, prototype, etc
  • Quick - just a couple of regexs
  • Lightweight - 1.35K minified
  • To change the appearance, just edit apache_prettify.css

Read more Comment


Validate a credit card number in JavaScript

Nick Nettleton | 12 August 2007

When you're writing web apps, it's good to do validation both in the browser and on the server side. Do it in the browser to provide your user with instant feedback, and on the server for real security, as all client-side validation can be tricked or circumvented by those who know how.

Validating credit card numbers is a little tricky. They all follow a special algorithm, whose name I forget. But here are the mechanics of it...

Read more 1 comment


JSON - better than XML?

Nick Nettleton | 02 July 2006

JavaScript coders have been doing it for ages. Now it's got a name: JSON, or JavaScript Object Notation.

One of the sexier features of JavaScript is a shorthand notations for defining and populating a data structure containing objects and arrays. So, instead of:

me          = new Object() ;
me.name = 'Nick' ;
me.age = 30 ;
me.hobby = new Array()
me.hobby[0] = 'Reading' ;
me.hobby[1] = 'Writing' ;
me.smelly = false ;

You can do this...

Read more 4 comments


Trim a string in JavaScript

Nick Nettleton | 01 July 2006

I've seen all kinds of techniques used to trim a string in JavaScript, some of them a bit bonkers. Here's the 'right' way:

var trimmed = str.replace(/^\s+|\s+$/g, '') ;

So there.

Permalink 65 comments