Accessing results of JavaScript's "window.confirm" in regular Java
I have a Java page that uses embedded JavaScript to create a confirmation message (I'm using window.confirm). I would like to use the results of the user's selection (either "Yes" or "No") outside of that JavaScript snippet but I'm not sure how. To clarify, I know how to check the user's selection in JavaScript but I am trying to pass that along to rest of the page, which is written in Java.
Supose I saved that result in a hidden field on the client side and wanted to pass that value as an argument back to the server to be used in Java. Would that be possible? And if, so, what is the correct synthex to access the value of that hidden field or other intermediary object?
UPDATE: The decision is to whether or not I want to save a record to a database. Clicking on the Save button brings up the Confirmation box (written in JavaScript) and also triggers a postback triggering and within a DoGet event that follows I would like to be able to tell what the result was so that I can know whether or not to proceed with saving.
There may be a delay in my future responses.
UPDATE #2: I was able to find a solution. To prevent the postback from happening after clicking the "No" button. I just needed to add:
{ event.returnValue = false; return false; } // simply开发者_开发问答 using return false by itself didn't help
This page really helped:
Yes, you can dynamically add a <input type="hidden" name="yes"/>
tag to a form and then let the user submit the form when ready.
Or you can use Ajax--which also has the advantage of being able to work asynchronously (without necessitating an entire page refresh).
精彩评论