JavaScript Tutorial - 5

Ahh ... but what makes JavaScript really exciting is the ability to make your page respond to what the viewer does. For example ... when a button is pressed :o)

In case you've never put a button on a page before, here's the html you need:

<form> <input type=button value="please press me"> </form> Task 12: Produce a page with a button. Check.

Amazingly easy ... but ... what's that? ... pressing the button didn't do anything?
Well let's see if we can rectify that.

The secret is the magic word onClick. You use it like this:

<form> <input type=button value="please press me" onClick=alert("Hello!")> </form>

Task 13: I bet you can't guess what Task 13 is :o) Check.

And you've learnt another Javascript word: alert. It's known as a function.
Functions are easy to recognise because they have (round brackets) after them.

Task 14: Find as many functions as you can from our previous work. But, please note, the ones with new in front of them are objects not functions. And also note that the brackets are right next to the function name. I found 8 including alert(). Check.

Challenge 6: Write a 2000 word essay on the difference between a variable and ...
No ... just kidding! Challenge 6 is to spend more time studying the answer to Task 14.

HOME Table of Contents Previous Next