Using a JavaScript function as a listener