开发者

Accessing results of JavaScript's "window.confirm" in regular Java

开发者 https://www.devze.com 2023-03-11 10:01 出处:网络
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\") outsi

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号