Jump to content

Replace document.write with innerHTML


Recommended Posts

Hello,

I'm currently using document.write in a report datapage to create conditional formatting in an HTML block column. (See last column of this link). I am having an error wherein the second page of the report omits the last column.  I asked caspio support and they said it is may be because I am using document.write, which is no longer supported in the new upgrade. They suggested using innerHTML, alert(), but I'm not sure how to modify the code. Any advice? Also, Is it possible that document.write is not the problem?

<script>
if ("[@field:tblRareTaxonTable_ProfileStatus]" == "Active") {
document.write("<div style='background:#A0CE4E;border:1px solid #000000;padding:5px 10px;'><span style='font-size:16px;'><strong><a href='https://saveplants.org/national-collection/plant-search/plant-profile/?CPCNum=[@field:tblRareTaxonTable_CPCNumber]' <span style='color:#482441;'>Go To Profile</span></a></strong></span></div>");
}
else {
document.write("<div style='background:#482441;border:1px solid #000000;padding:5px 10px;'><span style='font-size:16px;'><span style='color:#FFFFFF;'><strong>Profile In Progress</strong></span></span></div>");
}
</script>

Thanks so much for your help!

Katie

Link to comment
Share on other sites

Hi @Heineperson,

You can try following code with inner HTML:

<div id='record[@cbRecordIndex#]'></div>

<script type="text/javascript">
debugger;
document.addEventListener('DataPageReady', function (event) {
  
       if ("[@field:tblRareTaxonTable_ProfileStatus]" == "Active") {
document.write("<div style='background:#A0CE4E;border:1px solid #000000;padding:5px 10px;'><span style='font-size:16px;'><strong><a href='https://saveplants.org/national-collection/plant-search/plant-profile/?CPCNum=[@field:tblRareTaxonTable_CPCNumber]' <span style='color:#482441;'>Go To Profile</span></a></strong></span></div>");
   }
else {
document.write("<div style='background:#482441;border:1px solid #000000;padding:5px 10px;'><span style='font-size:16px;'><span style='color:#FFFFFF;'><strong>Profile In Progress</strong></span></span></div>");
   }
  
});
</script>

Hope this helps.

Regards,

vitalikssssss

Link to comment
Share on other sites

  • 1 month later...

Hi @Heineperson,

Sorry, I forgot to add inner HTML in my code. Please try to use the following code:

<div id='record[@cbRecordIndex#]'></div>

<script type="text/javascript">

document.addEventListener('DataPageReady', function (event) {
  
       if ("[@field:tblRareTaxonTable_ProfileStatus]" == "Active") {
document.getElementById("record[@cbRecordIndex#]").innerHTML="<div style='background:#A0CE4E;border:1px solid #000000;padding:5px 10px;'><span style='font-size:16px;'><strong><a href='https://saveplants.org/national-collection/plant-search/plant-profile/?CPCNum=[@field:tblRareTaxonTable_CPCNumber]' <span style='color:#482441;'>Go To Profile</span></a></strong></span></div>";
   }
else {
document.getElementById("record[@cbRecordIndex#]").innerHTML="<div style='background:#482441;border:1px solid #000000;padding:5px 10px;'><span style='font-size:16px;'><span style='color:#FFFFFF;'><strong>Profile In Progress</strong></span></span></div>";
   }
  
});
</script>

Regards,

vitalikssssss

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...