[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Pass function to function

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
tonelm54
Asked:
tonelm54
1 Solution
 
leakim971PluritechnicianCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now