Solved

Pass function to function

Posted on 2013-11-13
1
272 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
ID: 39644756
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article discusses how to create an extensible mechanism for linked drop downs.
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)
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…

805 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