I want to make a function that will constantly check that the input field is not more than 10 elements, I want to make it through the event handler, how to put conditions in the function?

<input type="text" maxlength="10" name="answer" id="t" onkeyup="isAllowedSymbol(this);" onchange="checkLength(this);" placeholder="Enter data" > function checkLength(obj) { var element = document.getElementById('t'); var e = document.createEvent('HTMLEvents'); e.initEvent('change', false, true); element.dispatchEvent(e); alert("ivalid length - 10 characters only!"); return element; } 
  • one
    So you have a limit in the attribute maxlength worth - Invision
  • Worth looking towards t.value.length - pepel_xD

0