You can call a JavaScript function from a Button click event without any problem. You can also call a document level JavaScript. Please refer to the help documentation about the JavaScript for the sample code.