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
Solved

Regarding JavaScript alert from action class in struts 2

Posted on 2010-09-17
8
2,499 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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

809 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