Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Regarding JavaScript alert from action class in struts 2

Posted on 2010-09-17
8
Medium Priority
?
2,747 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

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.
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…
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)

609 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