0

I have trouble make href dynamically> I want to put json type variable as parameter. As below, I want to change filename dynamically.

var fname=file_info.data.file_name;
        alert(fname);


        var rowNode = table.row.add( [
            "",
            status,
            res.data.client_name,
            wtax_file_type,
            month,
            res.data.tax_date,
            total_amount,
            "<button class='btn btn-xs btn-default'><a href='/wtax2/download?filename=312.pdf' id='file_download'><i class='icon-file-pdf text-error'></i><span>파일이름.pdf</span></a></button>",
            "<a class='btn-link color-primary'>[이동]</a>"
        ] ).draw().node();

currently a tag href parameter is set for filename=312.pdf. But i want to make it dynamically. how can i write code here??

1
  • Well, if you dynamic filename is "fname", then: <a href='/wtax2/download?filename='+fname+'.pdf' id='file_download'> Commented Feb 27, 2018 at 7:33

2 Answers 2

1

It looks like you already have variable set, called fname.

If this variable is holding your filename you can just attach it to your add() function.

var fname=file_info.data.file_name;
        alert(fname);


        var rowNode = table.row.add( [
            "",
            status,
            res.data.client_name,
            wtax_file_type,
            month,
            res.data.tax_date,
            total_amount,
            "<button class='btn btn-xs btn-default'><a href='/wtax2/download?filename="+fname+"' id='file_download'><i class='icon-file-pdf text-error'></i><span>"+fname+"</span></a></button>",
            "<a class='btn-link color-primary'>[이동]</a>"
        ] ).draw().node();
Sign up to request clarification or add additional context in comments.

Comments

0

As you have already id to your anchor, so you easily set it dynamically.

var fileLink = document.getElementById('file_download'); // get element by id
fileLink.href = "someurl";

OR if your variable fname is dynamic then you can set is as follow.

var fname=file_info.data.file_name;
        alert(fname);


        var rowNode = table.row.add( [
            "",
            status,
            res.data.client_name,
            wtax_file_type,
            month,
            res.data.tax_date,
            total_amount,
            "<button class='btn btn-xs btn-default'><a href='/wtax2/download?filename="+fname+"'.pdf'  id='file_download'><i class='icon-file-pdf text-error'></i><span>파일이름.pdf</span></a></button>",
            "<a class='btn-link color-primary'>[이동]</a>"
        ] ).draw().node();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.