Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Using a button to run a script

To write scripts using buttons, we will first need to know how to place a button on the page. To do this, you will need to use the <form> and <input> tags to set up a button tag or you can just use the <button> tag.

Here's an example that puts a message in the status line when you click the button:

<button name="button1" onClick="window.status='You 
clicked the button!'; return true">Click me</button>

Here’s a script that lets you change the background color of your page:

<button name="button2" onClick="document.bgColor='
yellow'">Change me</button>

What about using your button as a link? Here is a script that will send you to another page:

<button name="button3" onClick="window.location='
filters.htm'">Look at this</button>