Saturday 17 January 2015

Event Handler II



  • onReset: An onReset event handler executes Javascript code when the user resets a form by clicking on the reset button.
For example:


<html>
<head><title>Example of onReset Event Handler</title></head>
<body>
<h3>Example of onReset Event Handler</h3>
Please type something in the textbox and press the reset button:<br>
<form onReset="alert('This will reset the form!')" >
<input type="text">
<input type="reset" value="Reset form">
</form>
</body>
</html>   

In the above example,when you push the button "Reset form" after typing something,the alert method displays the message, "This will reset the form!".

  • onSelect: An onSelect event handler executes Javascript when the user selects some of the text or texture field.

For example:

<html>
<head><title>Example of onSelect Event Handler</title></head>
<body>
<h3>Example of onSelect Event Handler</h3>
Select the text from the text box:<br>
<form>
<input type=textbox value="Select this" onSelect="alert('This is an example of onSelect !!')">
</form>
</body>
</html>  

In the above example,when you try to select the text or part of the text,the alert method display the message, "This is an example of onSelect!!".

  • onSubmit: An onSubmit event handler calls Javascript code when the form is submitted.
For example:

<html>

<head><title>example of onSubmit Event Handler </title></head>

<body>

<h3>Example of onSubmit Event Handler</h3>

Type your name and press the button<br>

<form name="myform" onSubmit="alert('Thank you' + myform.data.value + '!')">

<input type="text" name="data">

<input type="Submit" value="Submit this form">

</form> </body> </html> 

In this example,the onSubmit event handler calls an alert( ) function when the button "Submit this form" is pressed.

  • onUnLoad: An onUnLoad event handler calls Javascript code when a document is exited.

For example:

<html> <head>

<title>onUnload Example</title>

<script>

function goodbye() {

  alert("Thanks for visiting!");  }

</script> </head>

<body onUnLoad="goodbye()">

<h3>Example of onUnload Event Handler</h3>

Look what happens when you try to leave this page...

</body> </html>   

In this example,the onUnLoad event handler calls the goodbye( ) function as user exits a document.

NOTE: You can also call Javascript code via explicit event handler call. For example, say you have a function called myfunction( ). You could call this function like this:
   document.form.mybutton.onClick= myfunction

Notice that you don't need to put the ( ) after the function and also the event handler has to be spelled out in lowercase. 

  



No comments:

Post a Comment