Just change the way the JavaScript block is loaded to no wrap (head)
The standard setting here is that the JS is wrapped(!) to be run after the DOM has loaded. That means the function is not defined in global scope but inside the wrapper. Inline event handlers only work with globally defined functions though!
When setting to no wrap (head)
the JS is loaded in the <head>
and is not wrapped.