34,333
edits
Changes
no edit summary
</pre>
Load the HTML file into JavaScript enabled browser and a web page will be displayed shwoing the text "Hello World". All that this script does is define the standard HTML tags that you would expect to see in an HTML page , and also defined define embedded JavaScript code that writes text out to the current document (''document'' is the JavaScript object for a web page).
Previously we discussed the event driven nature of JavaScript. In the next example we will extend the "Hello World" example to include event handling, in this case designing our script to display an alert dialog when a button is pressed.
</pre>
When loaded into a web browser the page will appear as before, but this time a push button is visible in the page which, when pressed, will display an alert dialog containing the words "Goodby Goodbye cruel world". In order to make this happen we have used the HTML ''<form>'' and ''<input>'' tags to make the button visible and combined this with the onClick event handler. We've specified that when the onClick event of the button is triggered (i.e when the user clicks on it) then the JavaScript to display the alert dialog should be executed.