Page 180 - DCAP408_WEB_PROGRAMMING
P. 180
Web Programming
Notes onSubmit
The onSubmit event is used to validate ALL form fields before submitting it.
Below is an example of how to use the onSubmit event. The checkForm() function will be
called when the user clicks the submit button in the form. If the field values are not
accepted, the submit should be cancelled. The function checkForm() returns either true or
false. If it returns true the form will be submitted, otherwise the submit will be cancelled:
<form method=”post” action=”xxx.html” onsubmit=”return checkForm()”>
onMouseOver and onMouseOut
onMouseOver and onMouseOut are often used to create “animated” buttons.
Below is an example of an onMouseOver event. An alert box appears when an onMouseOver
event is detected:
<a href=”a.html” onmouseover=”alert(‘An onMouseOver event’);return false</a>
Task Create a web page, which has an image file. Use the onMouseDown event handler,
which will resize the image when the user presses a mouse button over the image.
6.2.1 Event Association
Events are associated with HTML tags. The definitions of the events described below are as
follows:
abort - A user action caused an abort of an image or document load.
blur - A frame set, document, or form object such as a text field loses the focus for input.
click - Happens when a link or image map is clicked on.
change - Happens when a form field is changed by the user and it loses the focus.
error - An error happened loading a image or document.
focus - A frame set, document, or form object such as a text field gets the focus for input.
load - The event happens when an image or HTML page has completed the load process in
the browser.
mouseOut - The event happens when the mouse is moved from on top of a link or image
map.
mouseOver - The event happens when the mouse is placed on a link or image map.
reset - The user reset the object which is usually a form.
submit - The user submitted an object which is usually a form.
unload - The object such as a framesed or HTML document was exited by the user.
Task Create a web page, which has a text hyperlink and an image file. Use the onClick
event handler to display an alert when the link is clicked and the onDbClick event handler
to display an alert when you double click on the image.
174 LOVELY PROFESSIONAL UNIVERSITY