Javascript Form How to - Handle click event for input element








Question

We would like to know how to handle click event for input element.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--  w  w  w  .  jav  a2  s .  c o m-->
document.getElementById("input_file").onclick = function(){
    console.log('you clicked me');
};
}
</script>
</head>
<body>
  <input id="input_file" placeholder="click me" />
</body>
</html>

The code above is rendered as follows: