[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Pass function to function

Posted on 2013-11-13
1
Medium Priority
?
279 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
[X]
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
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

656 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