use event listener to handle validation