Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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

Win a copy of The Software Craftsman this week in the Agile forum!
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: 31672

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]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62298

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Have you tried LearnNowOnline?
subject: Returning Parameters from Javascript to Java