Javascript Sample 2: onkeypress and runtime style changes

This example shows how you can execute Javascript in response to keyboard events. It also illustrates how to modify an element's CSS style (in this case, the background-color) from within Javascript.

This box is red

Type g, r, or b to change the color to green, red, or blue.