Button with external javascript
Button with external javascript
I have a table with buttons that point to pdf documents:
{"mdata": null,
"data": "pk",
"bSortable": false,
"render": function(data) {
return '<a class="btn btn-info btn-sm" href=pdf/'+ data +'>PDF</a>';
}
},
my current <a href> I would like to replace the button:
<button type="button" onclick="printJS()">
Print PDF
</button>
printJS is a external JS
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm not entirely sure I understand the issue I'm afraid. You have it outputting an
atag at the moment and you want to have it output abuttontag instead. If that is correct, why not just update thereturnstatement to do that?Allan
I need put onclick="printJS() into my <a href>
What do you mean? I thought you were going to replace your "a href" tag with the "button" tag.
I'm a bit confused as well. I don't understand why you can't just put your DOM0
onclickevent in like you are doing with the other attributes (hreffor example)?More generally, I would suggest you don't use DOM0 event. Use jQuery events instead.
Allan
I have line of code:
which returns:
and I would like to return a 'my_link / 1' in quotes:
You just need to escape the quotes then. The MDN docs have an excellent description of how to use strings in Javascript.
Allan
Allan you are great this is what I meant.
Thank you very much.