Why are you trying to define this in your template file? Put the function in a JS file, bind the event handler like normal, and then link the JS file on your page.
EJS, like other template solutions, should only handle view logic. So, if you want to display the user's name or loop through an array and create a list of items, EJS makes it easy to do that before the web page has been sent to the user. For this, you'll want to stick with AJAX.