If the form generated by pressing the button refreshes a data view of that page, then you can put your js in a javascript snippet widget and select refresh on context change. The placement of this widget will need to be in the data view that is being refreshed. The widget should automatically run the js after everything is loaded.
Widget: https://appstore.home.mendix.com/link/app/43096/Incentro-Business-Acceleration/JavaScript-Snippet