Making websites do things
In an article in August's Journal, I provided a brief guide to the basic elements required to set up websites. While that article focused on a formatting language called HTML, I hinted towards the end of it that if you wanted to get yourself into a position where you could start identifying novel ideas for solicitors’ websites, then you should have a look at another computer language called Javascript. I suppose I had better put my money where my mouse is and provide an example. The following script is an example of how Javascript can make an otherwise static page actually do something. The example given here is not the sort of thing which you would want to put on a public site, but illustrates quite well some basic principles of how Javascript works. If you bear with me, I'll give an example at the end of how the techniques illustrated here have been used to do something practical.
The script
Anyone who has used the new CD version of McEwan and Paton will be familiar with its Retail Prices Index gadget which allows you to update the value of an award made in an old case to reflect its worth at today's prices. The following script does much the same thing at a simpler level. For the purposes of this illustration, however, it shows:
- the way in which HTML can place 'form elements' on screen, such as text input areas and select menus, to allow information to be fed into the screen.
- the way in which elements on screen can have 'event handlers' attached to them, to tell the script to start processing information given to it.
- the way in which a 'function' is set up in order to manipulate information and return a result.
This is what it should like on screen:
A case worth £xxxxx in xxxx year, is now worth £xxxxx, reset.So, here's the script (don't type the line numbers in, they're just for guidance):
- A case worth £ in
- is now worth
How it works
Well, there's a bit more going on there than in my August article, so let's break down what's happening. At line 13, the words tell the computer to put a text input box on screen. Giving it a name, 'then', allows the script to identify this particular form element, so that when information is typed into it, the script knows where it is coming from. In this script, 'then' is the box into which the old value of the case is typed. When you type a figure into the box, the figure is referred to as its 'value'.
You should maybe also notice at this stage that 'then' and the other form elements at lines 14, 24 and 25 are all contained within an overall