Solved

Pass function to function

Posted on 2013-11-13
1
270 Views
Last Modified: 2013-12-05
Ive been looking at ways to create warnings as dialogue boxes, but then if the user clicks 'Confirm' then to run additional code (eg to delete something).

I want to be able to pass what to do into the function, to eliminate having to write the function several times to do the same thing, so I came you with an addition from a working example:-

    function createDialog(title, text, onClose) {
    return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
    .dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            "Confirm": function() {
                $( this ).dialog( "close" );
				onClose;				
				},
            Cancel: function() {
                $( this ).dialog( "close" );
				}
			}
		});
	}

	$(document).ready(function (){
		createDialog('Confirm deletion!', 'Do you really want to delete this package?', function () { alert('hi'); } );
    });

Open in new window


However either Im declaring the function incorrectly, or trying to call it incorrectly as I dont get the 'hi' alert back, no error messages or anything in the console, however it is displaying the dialogue correctly, just not the alert.

Can someone advise me what Im doing wrong please?

Thank you
0
Comment
Question by:tonelm54
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
test page : http://jsfiddle.net/WZL6t/1/
replace :
    function createDialog(title, text, onClose) {
    return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
by :
    function createDialog(title, text, onClose) {
var onClose = onClose; // Huh??? LOL
    return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")

and run it inside your confirm using parentheses :
onClose() instead onClose
0

Featured Post

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!

Join & Write a Comment

by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
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…

728 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

12 Experts available now in Live!

Get 1:1 Help Now