I am using React if that helps.
I'm working on some user actions analytics for my website which has a form. I'm adding a logger on some user actions. One of them being I want to log every time the user clicks on the input field to enter some value into it. How can I achieve this functionality?
I was thinking of onClick but I don't think that would be the best way to go about it cause that wouldn't serve the purpose.
CodePudding user response:
I'm not exactly sure why you're claiming an onclick event wouldn't be the right approach.
You can add an ID to the input tag and access it through a JavaScript file, adding an onclick event to it.
<!DOCTYPE html>
<html>
<body>
<input type="text" id="test">
<script>
document.getElementById('test').onclick = function() {
console.log('An input field with the id "test" has been clicked.')
}
</script>
</body>
</html>
CodePudding user response:
<input onClick={logCount}>
more info about events: https://reactjs.org/docs/handling-events.html