Your clarion code creates the JavaScript and sends it to the server.
The JavaScript then does another request if you want the action to go ahead.
Remember this is all completely asynchronous, so you need to think in a very request / response kind of way. (and remember each request starts a new thread...)