Assignment 009
JavaScript, Form Objects, and Event Handlers
JavaScript is often utilized with HTML forms. HTML Forms are the Web equivalent to paper forms that we often fill out, such as survey forms, contest forms, and application forms. HTML forms are composed of text boxes, check boxes, radio buttons, and rectangular buttons.
Below is a form button:
Here is the HTML code to generate the button:
<form>
<input type="button" value="click me" name="donothingbutton" id="donothingbutton" />
</form>
The above button does not respond when clicked. In order to have a button do something, you must set it up to respond to an event. Buttons have several events to respond to, including:
- onClick - The onClick event (when something is clicked)
- onDblClick - The onDblClick event (when something is clicked twice)
- onFocus - The onFocus event (when something receives the tabe our mouse 'attention'
- onLoad - The onLoad event (whent the page loads)
- onUnload - The onUnload event (when the page is unloaded - user leaves the page)
Here is another button that includes the onClick" event handler:
Here's the code to generate the button.
<form>
<input type="button" value="click me" name="alertbutton" id="alertbutton" onClick="window.alert('You have just clicked me!');" / >
</form>