I have a situation where I want to call a function from document ready and on click.
var load_report = function(params) {
report_name = params.data.report_name;
// code continues
}
I can call it on click -
$("#report-" + report_name).click({'report_name': report_name}, load_report);
However, I also want to call if from $(document).ready() if certain constraints are met -
$(document).ready(function() {
if (($.url().param()) && ($.url().param('report_name'))) {
report_name = $.url().param('report_name');
// Call load_report with report_name parameter
}
}
I have tried - load_report({'report_name': report_name}), $.call({'report_name': report_name}, load_report), $({'report_name': report_name}, load_report); and none of them work.
load_report({'report_name': report_name}) looked the simplest and most promising, but fails on params.data.report_name because params.data is undefined. Basically, all I need to do here is convert the dictionary into a format that can be interpreted the same way as it is with the .click() event data.
My question is - how do I call load_report function with my parameters without binding it to an event?