Solved

Regarding JavaScript alert from action class in struts 2

Posted on 2010-09-17
8
2,431 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
  • 4
  • 3
8 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 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
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33702098
It will enter the if condition only if you click on yes.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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:gurvinder372
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:gurvinder372
ID: 33722143
thanks for the points
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now