Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial