How to call a JavaScript function based on an event

My 89-year old father-in-law is in the early stages of dementia. Every time he receives a scam email or malware alert he falls for it and uses his the credit card. I'm writing a Safari extension to display a warning message. I want to call the function only when something is entered in a text field (i.e. when he is about to use his credit card) to remind him. This code displays the alert all the time; I'm unclear on how to use the onkeypress event to call a function correctly. I know squat about JavaScript and the examples I found on the web assume I'm trying to embed the script into html. Any help is appreciated.


            function watchOut() {
                var msg = "DON'T USE THAT CREDIT CARD!";
                alert(msg)
            }


            // call the function (this does not work)
            onkeypress = watchOut();