You can't do it that way.
The embedded
Java in yout Javascript function has executed when the page was being formed to send to the browser, long before the user even saw the form on the page. The only way you can interact with the server is via the form submission.