This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Confirm using Java Script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Confirm using Java Script" Watch "Confirm using Java Script" New topic
Author

Confirm using Java Script

Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
Hi,
I have an application where in the user clicks on a delete Data button.

I want to use java script to confirm deletion and call the action handler only if he clicks ok.

Is there some way to this.

If so could you please give some kind of code structure.

Thanks in advance
Karthik
mona mittal
Greenhorn

Joined: Jan 26, 2006
Posts: 7
You can call a javascript function on "onClick" event and in this javascript function have something like an confirm() dialog which have Ok and Cancel buttons. Later you can handle your processing depending upon what user clicks, i.e. Ok or cancel.

Hope that helps!
Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
Hi,

I have tried that and it does not work. it submits whether userr clicks ok or cancel.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I've used this technique often, and it works fine for me. Here's some sample code.

<input type="button" value="delete" onklick="if (confirm('Are you sure?')) this.form.submit();" >


Merrill
Consultant, Sima Solutions
Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
Thanks a lot Merrill. That works.

Karthik
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Confirm using Java Script
 
Similar Threads
Struts html:button behavior question!
how to add a confirmation to user? -urgent
Alert and confirm message screens
Implementing the child window in JSF.
Returning Parameters from Javascript to Java