<< Previous Next >>
Tutorial home...

JavaScript confirmation box example #1

Input Data:


To do really simple things in JavaScript it is not necessary to write any of your own functions at all. In this example a form is created with some JavaScript code defined for its ONSUBMIT event handler. This event handler is defined within the FORM tag.

The JavaScript code is as follows:-

return confirm('Are you sure you want to submit this data?')

Note: the use of single quotes surrounding the string passed to the built in confirm() function. The reason for this will be clear when you view the HTML for this page (Select View|Page Source from the menu). It is because the ONSUBMIT value defined in the FORM tag has to be surrounded by double quotes. You must alternate between double and single quotes so that the JavaScript interpreter does not get confused and complain about unterminated string literals.


<< Previous Next >>
Tutorial home...