Add click event handler for input button in JavaScript

Description

The following code shows how to add click event handler for input button.

Example


<!DOCTYPE html>
<html>
<head>
<!--from   w  w  w  .j  ava  2  s.  co  m-->
</head>
<body>
<Form name="aForm">
<Input type="Button"
name="Big_Button"
value="Big Button"
onClick="onClickHandler(this)";>
</Form>
<script type="text/javascript">
function onClickHandler(elem) {
document.writeln("java2s.com");

}
</script>

</body>
</html>

Click to view the demo

The code above generates the following result.

Add click event handler for input button in JavaScript
Home »
  Javascript Tutorial »
    Form »
      Button
Javascript Tutorial Button
Access form button with its name through do...
Access form with form name through document...
Add click action to a Button in JavaScript
Add click event handler for input button in...
Add click event handler to input onClick ev...
Change input button color and background co...
Get current value of the submit button whic...
List properties from a form button in JavaS...
Return false in form button click event to ...
Use Image as the submit button in JavaScrip...