JavaScript: Using Variables To Hold State

On form objects, you can change the onClick property. In this example, we have a small form with just a button. Each time the button is pressed, it does something different. The JavaScript code for this demonstrates using variables to keep track of information between events and does several things with changing CSS properties on the page.

<form name="form1">
<input name="button1" type="button" value="Click me" onClick="return pressme();"></input>
<span id="mesg"></span>
</form>