Jeff Mcbride
Jeff Mcbride

Reputation: 453

JavaScript not functioning correctly in JSReport

trying to use document.getElementById() in jsreport using the scripts section on the left menu, but it reports back

Error occured - Error during rendering report: document is not defined

What gives? This is simple JavaScript to target a particular ID.

Upvotes: 2

Views: 1275

Answers (2)

Jeff Mcbride
Jeff Mcbride

Reputation: 453

The problem is asynchronous related. the document.getElementById must come after the the element you want to target is built. So putting the script at the bottom of the page fixes the issue.

Upvotes: 0

R. Salisbury
R. Salisbury

Reputation: 2006

Scripts that are included as part of the report generation request rather than inline with the template do not contain document or any other objects generated by the browser.

If you are trying to use Javascript to modify the document, you are almost certainly doing something wrong. It's not meant to generate interactive content, so your template and data should already be fixed by the time you send the request. You can probably work around this with require.js, but why would you? If you are really generating a report, you can do everything ahead of time before you ever request output.

Upvotes: 0

Related Questions