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

problem with popup delete jquery model

Posted on 2010-11-20
4
636 Views
Last Modified: 2012-08-14
im trying to make a dialog popup for a delete confirm yes/cancel and im having a very hard time with it
it keeps breaking and i can do it to save my life

please understand i need to put this into a php page i have and pass the id to another php script
also note the image to be clicked for delete is in a php include on another page.
heres what i have thats no longer working
<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  
<script type="text/javascript">
$(document).ready(function(){
  $("#dialog-confirm").dialog({
                              modal: true,
                              bgiframe: true,
                              autoOpen: false }); 
});


	function confirmDelete(username, id) {
		var username = 'johnny';
		var id = '2';
		$( "#dialog-confirm" ).append("Are you sure you want to delete: <br>'" + username + "' with id: "+ id);
 		$( "#dialog-confirm" ).dialog({
    			show: "blind",
    			hide: "explode",
 			resizable: false,
 			height:220,
 			modal: true,
 			buttons: {
				"Yes": function() {
				var delUrl = "testimonial_delete_id.php?id='" + id+"'";
				window.location.href = delUrl; },
				
				Cancel: function() {
				$( this ).dialog( "close" );
				}
 			}
 		});
 	};
	
	$("#opener").click(function() {
		$("#dialog-confirm").dialog( "open" );
		return false;
	});
 </script>
</head>
<body>
 
<div id="dialog-confirm" title="Warning: Delete Recrod" style="font-size:10px;"><p><span class="ui-icon ui-icon-alert"></span>This item will be <br><B style="color:#dc143c;">permanently deleted and cannot be recovered</B>.</p></div>
<?
$by_name2="fred";
$id2="5";
echo '
<A HREF="#" title"Click here to delete"  id="opener" onclick=\'confirmDelete("'.$by_name2.'",'.$id2.')\'><img src="images/icon_delete.png" width="16" height="16" border="0" /></A>
'
?>
</body>
</html>

Open in new window

 


thank you in advance for any code or help you may provide
0
Comment
Question by:Johnny
  • 3
4 Comments
 
LVL 18

Accepted Solution

by:
Sudaraka Wijesinghe earned 500 total points
ID: 34182088
Hi, pls see my comments in the code.
<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){

//Remove this and initiate the dialog box on click (in confirmDelete)
 /* $("#dialog-confirm").dialog({
                              modal: true,
                              bgiframe: true,
                              autoOpen: false });*/
});


        function confirmDelete(username, id) {
            	//To use the values passed as function parameters, don't initialize them here 
                //var username = 'johnny';
                //var id = '2';
                
                $( "#dialog-confirm" ).append("Are you sure you want to delete: <br>'" + username + "' with id: "+ id);
                $( "#dialog-confirm" ).dialog({
                        show: "blind",
                        hide: "explode",
                        resizable: false,
                        height:220,
                        modal: true,
                        buttons: {
                                "Yes": function() {
                                var delUrl = "testimonial_delete_id.php?id='" + id+"'";
                                window.location.href = delUrl; },

                                Cancel: function() {
                                $( this ).dialog( "close" );
                                }
                        }
                });
        };

        $("#opener").click(function() {
                $("#dialog-confirm").dialog( "open" );
                return false;
        });
 </script>
</head>
<body>

<!-- Note the display:none to hide it from displaying on the page -->
<div id="dialog-confirm" title="Warning: Delete Recrod" style="font-size:10px; display:none;"><p><span class="ui-icon ui-icon-alert"></span>This item will be <br><B style="color:#dc143c;">permanently deleted and cannot be recovered</B>.</p></div>
<?
$by_name2="fred";
$id2="5";
echo '
<A HREF="#" title"Click here to delete"  id="opener" onclick=\'confirmDelete("'.$by_name2.'",'.$id2.')\'>xxxxx<img src="images/icon_delete.png" width="16" height="16" border="0" /></A>
'
?>
</body>
</html>

Open in new window

0
 

Author Comment

by:Johnny
ID: 34182252
wow thats great thanks so much

now if i can get the idiotic jquery dataTables interface i used for my data display as i just broke the dang thing with this(its so XXX touchy)

i just cant win, got something great to work and it breaks something else. when i add it to the page.

but non the less thank you so much.

0
 

Author Closing Comment

by:Johnny
ID: 34182254
perfect thank you
0
 

Author Comment

by:Johnny
ID: 34182267
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
php56-php-mcrypt for rhel7 php56 1 44
Log in through ID 5 17
HowTo set a global variable in javascript or jQuery 4 21
Copying table data to one another 15 29
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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

808 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