HTML and CSS Reference
In-Depth Information
EXPLANATION ( CONTINUED )
5
The HTML input type is a text field named your_name , which will display up to
50 characters.
6
The HTML input type is a submit button. When the user clicks this button, the
onSubmit handler in line 4 is triggered. If the return value from the function
check_Form is true , the form will be submitted to the server, located at the URL
shown in the action attribute of the form named info .
Using the button Input Type Rather than submit . As shown in the previous
examples, before the browser sends data to the server, an onSubmit or onClick event han-
dler is triggered when the user clicks the submit button or presses the Enter key. But
what if you don't want the form to go off to the server? Then you will have to reject the
submission or the browser will reset all the field values to their defaults.
If the form is not going to submit data to a server, the button input type can be used
instead of the submit button. The button object has no default behavior and is used as a
triggering device so that when the user clicks the button, it causes something to happen.
The onClick event handler is commonly used with buttons and is set as an attribute of
the button input type. The onClick event handler is triggered when the user clicks the
button associated with it.
EXAMPLE 11.14
<html>
<head><title>button input type</title>
<script type="text/javascript">
1
function greetme(){
alert("Why did you click me like that? ");
}
</script>
</head>
<body>
2
<form name="form1">
<!-- event handler for a button is an attribute for its
input type -->
3
<input type="button"
value="Click me!"
4
onClick="greetme()" />
</form>
</body>
</html>
EXPLANATION
1
This function called greetme() is called when the user clicks the button device.
2
A form called form1 is started.
Continues
 
Search WWH ::




Custom Search