The above will work because it's executed on the client's machine, but the php code is parsed before the page is send to the client (on the server) so it is impossible to know when the user will click it.
However you can make an ajax call:
input type="text" onclick="$.get('page.php')">
And page.php will have a call to you function: <?call();"?>
This will work. (The above code uses jQuery library)