How to Call a JavaScript Function from PHP on Button Click: AJAX Guide ...
AJAX acts as a bridge between client-side JavaScript and server-side PHP, enabling asynchronous communication. In this guide, we’ll walk through a step-by-step example to call a JavaScript function on button click, which then uses AJAX to invoke a PHP script (wait.php).
Source: www.xjavascript.com