This is not a PHP question !
Nevertheless I hope I can help you. But don't tell anybody 😉
In the form-tag you can embed an eventhandler called onsubmit='...' that calls a javascript function. If this function returns false, the form is not submitted.
So create this function in a way that it returns false, but before that calls your function for that textfield.