-
JavaScript Functions & Event Handlers
JavaScript Functions & Event Handlers
JavaScript Functions
· A JavaScript function is a section of code perform a specific task That When called. Calling a function is achieved by its name.
The Unchained Tour offers the best Java training, and if you’re from Chennai make sure to check them out for your Java requirements
Syntax:
function function_name ()
{
function code
}
example:
<Html>
<Head>
<Script>
function helloFunction ()
{
alert ("Hello people!");
}
</ Script>
</ Head>
<Body>
<button onclick = "helloFunction ()"> Press button </ button>
</ Body>
</ Html>
Calling the Function:
<script type = "text / javascript">
<! -
helloFunction ();
// ->
</ Script>
Function with Parameters:
<script type = "text / javascript">
<! -
function cityFunction (city, code)
{
alert (city + "city code is:" + code);
}
// ->
</ Script>
Calling the Function with Parameters:
<script type = "text / javascript">
<! -
cityFunction ('London', 5);
// ->
</ Script>
Function with a Return value:
<script type = "text / javascript">
<! -
function fullname (firstname, lastname)
{
var name;
name = firstname + lastname;
return name;
}
// ->
</ Script>
Calling the Function with Return:
<script type = "text / javascript">
<! -
var thename = fullname ('Tom', 'Joe');
alert (thename);
// ->
</ Script>
JavaScript Events
JavaScript Events
A function is a section of code that performs a specific task when called. Calling a function is achieved by its name.
Syntax:
function function_name ()
{
function code
}
example:
<Html>
<Head>
<Script>
function helloFunction ()
{
alert ("Hello people!");
}
</ Script>
</ Head>
<Body>
<input type = "button" onclick = "helloFunction ()" value = "Press button" />
</ Body>
</ Html>
result:
JavaScript Event Handlers
Event handling is the action following the event, such as onClick, onMouseOver, onKeyUp. Drive or treating an event has a JavaScript function that will take over the tasks assigned to the event.
Event
Description
onBlur
Action that will be triggered when the element loses focus on.
we change
Action that will be automatically triggered when changing an item.
onFocus
Action that will be triggered by focusing on an element.
onreset
Action will be initiated when the reset button of a form is pressed.
onSelect
Action that will be triggered when selecting an item.
onSubmit
Will be initiated when the submit button of a form is pressed.
onclick
Action that will be triggered when you press left click on the mouse.
onDblClick
Action that will be triggered when you click on the left mouse button.
onMouseDown
Action that will be triggered when a mouse button is pressed.
onMouseMove
Action that will be triggered when the mouse cursor moves.
onMouseOut
Action that will be triggered when the mouse cursor moves outside or bounded.
onMouseOver
Action that will be triggered when the mouse pointer moves over an element or over the surface area.
onMouseUp
Action that will be triggered when the mouse button is released.
onKeyDown
Action that will be triggered when a key is pressed.
onKeyPress
Action that will be triggered when you press and release a key.
onKeyUp
Action that will be triggered when a key is released.
onError
Action that will be triggered after loading an image or failure of a document.
onload
Action that will be automatically triggered when loading a document.
onUnload
Action that will be automatically triggered when a document does not load.
-
Commentaires