File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Returning Parameters from Javascript to Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Returning Parameters from Javascript to Java" Watch "Returning Parameters from Javascript to Java" New topic

Returning Parameters from Javascript to Java

Padmalatha Kontham

Joined: Jun 21, 2007
Posts: 6

My requirement is to write a javascript for opening a confirm box on the click of a button. When the user clicks on "OK" button, the javascript should return a value "true" and when the user clicks on the "Cancel" button, "False" value should be returned.
I need to use these boolean variables outside the java script.
Is it possible for the javascript to return a value which can be used outside the script.

Please suggest me how to write the code for this.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33119

var result = confirm(); stores the result in a Javascript variable. You can use these within other Javascript on the same page. You can also use JavaScript to set a hidden form field with the value and pass it to Java.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63862

You'll need to explain what you mean by "outside the script". As Jeanne pointed out, you can submit it back to the server via a form submission, but to go into more detail you'll need to be more specific.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Returning Parameters from Javascript to Java
It's not a secret anymore!