JavaScript Events

JavaScript Events

The main purpose of JavaScript is to enable us to perform the actions we want when an event occurs on our page. In order to achieve this, the events that can occur on the page are given a name. In response to the desired event, we can call a javascript function and perform the relevant operations.

For example, if we want to run the calculate javascript function when a button is clicked, the onclick parameter is written in the button element as follows:

<input type="button" value="Calculate" onclick="calculate()" />

Let's explain the important events in JavaScript:

onClick

The element is clicked.

onDblClick

It is the event of double-clicking the element.

onLoad

The element is loaded. It can be the page itself, or it can be a picture or frame. If there is a function that is requested to run directly when the page is loaded, it can be called with this event:

<body onload="inputFunction()" >

onUnLoad

It is the abandonment of the open page in the browser. It can be by closing this window or clicking a link to switch to another page.

onFocus

It is the event of selecting and focusing an element. For example, when a text box is clicked, the control switches to that box and the box becomes active. There is an example of this in the next topic.

onBlur

It is the event that the active element is abandoned. For example, when a text box is active, a blur event occurs when clicking somewhere else and exiting the box.

onMouseOver

It is the event of hovering the element with the mouse.

onMouseOut

It is the event of moving the mouse cursor over the element.

onMouseMove

It is the event of moving the mouse cursor over the element.

onMouseDown

It is the event of pressing the left mouse button while on the element. As soon as the button goes down, the relevant function works.

onMouseUp

It is the event that the left mouse button is pressed and released while on the element. It doesn't work when the mouse button is down, it works when the button is released.

onKeyDown

It is the event of pressing a key on the keyboard. The ASCII code of the pressed key can be learned with the Event.keyCode property. The String.fromCharCode method can convert the read character code to the name of the key.

onSelect

The event of selecting text within a text box.

onResize

It is the event of changing the size of the browser window.

 

javascript events and function calling when event occurs, javascript event examples

EXERCISES

JavaScript Event Tutorials Try It

Click the Try It Yourself button, change the codes, see the result...



COMMENTS




Read 534 times.

Online Users: 67



javascript-events