event listener and function to create tables