File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JS confirm for h:commandButton?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JS confirm for h:commandButton??" Watch "JS confirm for h:commandButton??" New topic

JS confirm for h:commandButton??

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
I would like for a user to confirm that he/she wants to undertake a submit action. I have a h:commandButton and I would like to use the JS confirm function and the onclick attribute in order to do that. The problem is when I want to submit the form (once the user has clicked yes on the confirm button) and I do not want to hard-code the path to the form. Another problem is that I have several h:commandButtons on the form.
Can anyone please help?
Thanks in advance,
Julien Martin.

My code

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
I was given the solution by someone. Here it is:

Ronald Aguilar

Joined: Sep 14, 2004
Posts: 21
u can use this:

------------------------------------------------"return confirmationSave()"


<script type="text/javascript">

function confirmationSave() {

var answer = confirm("Confirm Save")

if (answer == true){
return true;
return false;


I agree. Here's the link:
subject: JS confirm for h:commandButton??
It's not a secret anymore!