Skip to content
Law Society of Scotland
Search
Find a Solicitor
Contact us
About us
Sign in
Search
Find a Solicitor
Contact us
About us
Sign in
  • For members

    • For members

    • CPD & Training

    • Membership and fees

    • Rules and guidance

    • Regulation and compliance

    • Journal

    • Business support

    • Career growth

    • Member benefits

    • Professional support

    • Lawscot Wellbeing

    • Lawscot Sustainability

  • News and events

    • News and events

    • Law Society news

    • Blogs & opinions

    • CPD & Training

    • Events

  • Qualifying and education

    • Qualifying and education

    • Qualifying as a Scottish solicitor

    • Career support and advice

    • Our work with schools

    • Lawscot Foundation

    • Funding your education

    • Social mobility

  • Research and policy

    • Research and policy

    • Research

    • Influencing the law and policy

    • Equality and diversity

    • Our international work

    • Legal Services Review

    • Meet the Policy team

  • For the public

    • For the public

    • What solicitors can do for you

    • Making a complaint

    • Client protection

    • Find a Solicitor

    • Frequently asked questions

    • Your Scottish solicitor

  • About us

    • About us

    • Contact us

    • Who we are

    • Our strategy, reports and plans

    • Help and advice

    • Our standards

    • Work with us

    • Our logo and branding

    • Equality and diversity

  1. Home
  2. For members
  3. Journal Archive
  4. Issues
  5. January 2001
  6. Making websites do things

Making websites do things

A guide to the basic principles of Javascript with a view to producing some practical results
1st January 2001 | Scott Cownie

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):

  1. A case worth £ in
  2. 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

element which opens at line 12, where it is given the name 'RPI', and closes at line 26. This idea of having a screen with a form on it and elements within the form is the basis of a heirarchical way of identifying things on screen, called the Document Object Model. For example, you'll see at line 6 that whatever figure is typed into the box 'then', is formally referred to as 'document.RPI.then.value'. The heirarchy steps down through the document as a whole, the name of the form on the screen, the name of the box within the form, and then the particular figure which is in the box at that point in time. Sticking with line 6 for a second, that unwieldy cluster is renamed as 'oldvalue', for reasons I'll explain later.

So, we've typed the old value of the case into 'then'. Next, we need to choose the year in which the case was decided. Lines 14 to 22 tell the computer to display on screen a select menu, one of those fancy little drop-down menus which you click to see a list of available options. It has opening and closing tag at line 14. Each of the options which you want to appear in the list are set up using

By now, you've told the page the sum awarded and the year it was decided in. How does the script work out its current value? In line 14, the