Here’s my JavaScript sample:
function createButtons(idDialog, tab, fn, param) {
var btns = new Array();
for (var i = 0; i < tab.length; i++) {
btns.push( {
text: (tab[i]>0 ? '+':'')+tab[i],
click: function(a) {
console.log(fn);
console.log(param);
fn(param);
$(this).dialog("close");
}
});
};
btns.push( {
text: "Close",
click: function() {
$(this).dialog("close");
}
});
$(idDialog).dialog('option', 'buttons', btns);
}
The params: fn is a function that should be called whenever we click the button, and param is a param that should be passed to the function.
When I use this code, console.log(fn) says undefined and console.log(param) says undefined. It kinddof doesn’t recall the param.
How should I do?
I’ve asked JoshNaro to answer but he didn’t so here’s the solution he gave that works perfectly: