using document.getElementById in a script to target a class id

209 views
Skip to first unread message

Jeff McBride

unread,
Nov 13, 2015, 5:29:38 PM11/13/15
to jsreport
I'm writing an if else statement to show and hide div's based of a JSON variable so I'm targeting the div like so:
var invalidRecords;
var numberUpdatedRecords;

   
if (invalidRecords === null || invalidRecords === "0")
   
{
       
var showInvRec = document.getElementById("showInvalidRecord");
        showInvRec
.style.visibility = false;
   
}
   
else
   
{
       
var showInvRec =  document.getElementById("showInvalidRecord");
       showInvRec
.style.visibility = true;
   
}
   
if (numberUpdatedRecords === null || numberUpdatedRecords === "0")
   
{
       
var showUpdRec = document.getElementById("showUpdatedRecords");
        showUpdRec
.style.visibility = false;
       
var showUpdRecFalse = document.getElementById("showUpdatedRecordsFalse");
        showUpdRecFalse
.style.visibility = true;
   
}
   
else
   
{
       
var showUpdRec = document.getElementById("showUpdatedRecords");
        showUpdRec
.style.visibility = true;
       
var showUpdRecFalse = document.getElementById("showUpdatedRecordsFalse");
        showUpdRecFalse
.style.visibility = false;
   
}


But for some reason when I run the report, I get the error:  "Error occured - Error during rendering report: document is not defined".  This js code is completely valid.  How do i target a specific div within a phantomPDF?

Jan Blaha

unread,
Nov 16, 2015, 2:07:27 PM11/16/15
to jsreport
Is this javascript located in the template content? 

Please note that scripts created in "Scripts" menu don't have access to the document, window or any other browser related objects. These scripts should be used rather to modify the rendering inputs than the document. More about it here

Jeff McBride

unread,
Nov 16, 2015, 2:43:55 PM11/16/15
to jsreport
Now I understand what the scripts file is for.  I tried accessing the document within the template content:

var red = document.getElementById("testHide");
    red
.style.color = "red";

with no success.  I can write to the document with document.write, but cannot target an element with
 document.getElementById();

Jan Blaha

unread,
Nov 16, 2015, 2:59:22 PM11/16/15
to jsreport

Jeff McBride

unread,
Nov 16, 2015, 3:02:59 PM11/16/15
to jsreport
So the script needs to be after the element apparently.

Jan Blaha

unread,
Nov 16, 2015, 3:06:47 PM11/16/15
to jsreport
As for every html and browser. 
Reply all
Reply to author
Forward
0 new messages