Solved

Regarding JavaScript alert from action class in struts 2

Posted on 2010-09-17
8
2,486 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 40

Expert Comment

by:gurvinder372
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: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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn how to implement Singleton Design Pattern in Java.
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)

831 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