How to limit number of characters in input field processing

I am new in CakePHP but I am starting to pickup fast -I have been a .NET developer, ASP/Razor pages for ever. So it is a bit of a learning curve. In .NET I have a javascript function that counts the number of characters as user enters information; I have been trying to implement a simple javascript to play around but cannot make it work.


<?= $this->Form->submit('Cancel',array('type'=>'button','onClick'=>"cancelFind();")); ?>

Java function - how do I declare this?? wrapped in <?= ?>:
function cancelFind(){
  alert('Do what you want to do!');

If you don’t really care where the JavaScript goes, you can just put it straight into your template without wrapping in <?= ?>.

If you need it in the header or footer, then the HTML Helper is your friend.