Display a table report and paste this code into the console:
var dbidTable = "your table dbid";
$("table[qbdbid=" + dbidTable + "] tr:first").before("<tr><td><a href=# id=QBU_Button class='Vibrant Success'>Pinch Me</a></td></tr>");
$("#QBU_Button").on("click", function(event) {
alert("Ouch!");
});
It will splice a button atop the report and establish a listener for clicks on that button. When you click the button the callback will execute in this case alerting a message.
To implement this you could set up the
IOL technique and include the IOL field
[-] in the report - typically as the last column of the report to not call attention to itself (it will be a skinny column). The formula for [-] will be just this:
[iol] & "myScript.js" & [/iol]
The code snippet you pasted is for setting up a button on each row of a report:
[iol] & "myScript.js" & [/iol]
&
"<a class='QBU_Button Vibrant Success'>Button</a>"
Although it would normally pass the
[Record ID#] through a data attribute:
[iol] & "myScript.js" & [/iol]
&
"<a class='QBU_Button Vibrant Success' " &
" data-rid='" & [Record ID#] & "'" &
">Button</a>"
And obtain the record id in the script as follows:
$("a.QBU_Button").on("click", function(event) {
var rid = this.dataset.rid;
var message = 'You clicked on record with rid=${rid}';
alert(message);
});
BTW, I think it is best to
always name your code page with the prefix "
module" followed by the name of the table and perhaps the function of the script. Examples:
moduleTable1.js
moduleTable1Form1.js
moduleTable1UpdateSomething.js