Button with external javascript

Button with external javascript

maltmalt Posts: 4Questions: 1Answers: 0

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

Answers

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    I'm not entirely sure I understand the issue I'm afraid. You have it outputting an a tag at the moment and you want to have it output a button tag instead. If that is correct, why not just update the return statement to do that?

    Allan

  • maltmalt Posts: 4Questions: 1Answers: 0

    I need put onclick="printJS() into my <a href>

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    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.

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    I'm a bit confused as well. I don't understand why you can't just put your DOM0 onclick event in like you are doing with the other attributes (href for example)?

    More generally, I would suggest you don't use DOM0 event. Use jQuery events instead.

    Allan

  • maltmalt Posts: 4Questions: 1Answers: 0

    I have line of code:

      return '<a class="btn btn-info btn-sm" onclick="printJS(my_link/ '+ data +')">pdf</a>'
    

    which returns:

    <a class="btn btn-info btn-sm" onclick="printJS(my_link/1)">pdf</a>
    

    and I would like to return a 'my_link / 1' in quotes:

     <a class="btn btn-info btn-sm" onclick="printJS('my_link/1')">pdf</a>
    
  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin
    Answer ✓

    You just need to escape the quotes then. The MDN docs have an excellent description of how to use strings in Javascript.

    Allan

  • maltmalt Posts: 4Questions: 1Answers: 0

    Allan you are great this is what I meant.
    Thank you very much.

This discussion has been closed.