JavaScript Examples


Inline Script


The user’s name is obtained by using the window.prompt() method. Default text was placed in the input field.

The user’s response is echoed using the window.alert() method. The message uses \n at the end of the question to force the user’s name to appear on the next line.

The instructions were embedded in the <body> tag and attached directly to the onLoad event.


Example by R. Hinton