?
Solved

Regarding JavaScript alert from action class in struts 2

Posted on 2010-09-17
8
Medium Priority
?
2,685 Views
Last Modified: 2013-11-24
I have a button called Delete in jsp page.when i click on it first it should show me an pop up alert to confirm the deletion.When click on yes it should call my action class method and there by should delete the record in database also.
How can give a javascript alert and click on yes it shoudl call my action class method.
I am using struts 2.0
please help me out.
0
Comment
Question by:SonyAgarwal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1000 total points
ID: 33701912
function method()
{
   if (confirm("should I carry on with deletion"))
  {
      //do struts action call
  }
}
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33701927
Use the onclick attribute of the button and "confirm" dialog box : http://www.w3schools.com/jsref/met_win_confirm.asp

 
<input type="button" value="delete" onclick="if( confirm('Really ?') ) deleteFunction();" />

Open in new window

0
 

Author Comment

by:SonyAgarwal
ID: 33702053
how can i call action class method on click of yes... in pop up alert.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 33702098
It will enter the if condition only if you click on yes.
0
 

Author Comment

by:SonyAgarwal
ID: 33702176
ok will try that way.Thanks
I have one more requirement of same java script please suggest me solution for this.
I have a drop down which has multiple values in that and for each value selected i will call action class there based on the value i selected i will make a different method call.So among the values in drop down i have a delete functionality.when i select delete from drop down and click on save it should not call action class first instead it should give be a alert saying "sure you want to delete " when click on yes it should call action class method.But in struts.xml file i mapped save button to action class now only for this situation how can i make a action class call.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 33704785
<select onclick="callAjax(this)">
  <option value="add">Add</option>
  <option value="del">Delete</option>
</select>

function callAjax(thisObj)
{
   if(thisObj.value="del")
   {
         if( confirm( "You really really wanna delete this?" ) )
         {
               \\ajax call  
         }  
   }
}
0
 

Author Comment

by:SonyAgarwal
ID: 33716921
<s:submit type="button" value="Delete" action="deletet" onclick="delete()" />

javascript call is not working with onClick command in struts 2 ...
its not going to that method call

<script language="javascript" type="text/javascript">
 function delete() {
 alert("cat");
 alert(dog);
 }
 </script>
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 33722143
thanks for the points
0

Featured Post

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question