Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
Calling JavaScript function in an Event
This article explains about calling a simple Java script function in an event .
Let's write a simple Javascript function and make it to fire on click event of command button. Event is something that can respond to particular action.
Each HTML control has got certain kind of events which can fires JavaScript functions. That JavaScript function needs to be assigned to event. We place event in html tag of the control itself. For example onclick event fires when we click on that control by any cast.
Some of the commonly used events are:
- onclick
- onblur
- onchange
- onkeypress
- onmouseover
- onselect
- onsubmit
- onfocus
Onclick This event is applicable to controls like button, radio button, check box, submit button etc.
<html>
<head>
<script>
function f()
{
alert('Hello! How are you?');
}
</script>
</head>
<body>
<input type ="button" value ="Click" onclick ="return f();" >
</body>
Execution of the Page:
When alert.html is executed form is loaded with a command button. Until and unless JavaScript function is called it doesn’t get executed. Here we have assigned f () for onclick. So JavaScript function is called as soon as we click on the button and the code in the function is executed. Hence we click on button an alert box is executed.
|
|