issue with Print with use from dropdown outside datatable
issue with Print with use from dropdown outside datatable

Hi,
As I have print button in Datatable. So print working fine. But I need your help with using the text from dropdown **outside ** datatables that it require to display text in print. So in Datatable. I use the buttons:
{
extend: "print",
text: "Print <i class='fas fa-print'></i>",
title: "Unit: " +
select_name(),
},
for Function:
function select_name() {
return $("#ddName option:selected").text();
}
So the problem is. when I change in dropdown and press print. the text does not change as it will use the previous text. not the one I have changed.
Can anyone help?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
is executed when the button is added to the table. You want to delay the fetch of the data from
select_ name()
until when the user actually presses the button. For exactly that reason,title
can be given as a function:Allan
Thank you allan. it has solved my problem