I am performing the following steps: 1- A textarea whose maxlength is 50. 2- A button on click of which text is getting appended to textarea.
Issue: Maxlength validation does not work if keep clicking the button. Don't want to put any check of maxlength on button click.
Is there any textArea eventlistener I can add to put a check if adding data on button click event.
<body>
<textarea id="test" rows="4" cols="50" maxlength="50">
</textarea>
<button onclick="appendData()"> Click </button>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
var txtArea = document.querySelector('textarea');
});
document.getElementById('test').addEventListener('change', function(event) {
alert('inside event listener of textarea 2')
})
function appendData(){
document.querySelector('textarea').value += "hello";
}
</script>
</body>