I’m trying to submit a dialog form when the user presses enter. I had the form setup as below:
$("#band-dialog-form").dialog({
buttons : {
"Save" : function(){
$(this).dialog("close");
$("#editBandForm").submit();
},
Cancel : function() {
$(this).dialog("close");
}
},
close : function() {
}
});
When I added the key listener I changed to:
"Save" : function submitBand(){
$(this).dialog("close");
$("#editBandForm").submit();
},
But my key listener can’t find the function submitBand. If I try and pull the function out of the dialog and make it:
"Save" : submitBand(),
The submitBand function is called on initialization and the page is sent without the user doing anything. What is the propper way to used named functions in the buttons object?
You are assigning the result of executing
submitBandto the “Save” key, as the parentheses followingsubmitBand(or “function call” construct) means “execute this function object and return the result”. Try passing the function object without the function invocation construct: