JavaScript onclick Event

The onclick event in JavaScript simply triggers when you click a specific control, such as button control.

JavaScript onclick Event Example

Here is an example demonstrates onclick event in JavaScript:

   <title>JavaScript onclick Event</title>

<h3>JavaScript onclick Event Example</h3>
<form name="myform">
   Name: <input type="text" id="name" value=" "><br/>
   <button onclick="alert('Hi ' + document.getElementById('name').value + ', Welcome to!')">Click Here</button>


Here is the sample output of the above JavaScript onclick event example. This is the initial output:

javascript onclick event

Now enter your name, and press on Click Here button, after pressing on that button, you will see an alert box showing an alert message as shown in the following snapshot:

javascript onclick event example

Here is the live demo output produced by the above onclick event in JavaScript.


JavaScript Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube