Jump to content
DesiLogi

Show or Hide html field in tabular datapage with javascript

Recommended Posts

Hello, 

In a tabular datapage I need to show/hide a field (text64000) that contains html markup and needs to display as html.

I use a div id to isolate each record in the tabular datapage's recordset.  Then I use an 'if' statement to check the values of 2 fields in that record ("field1" and "field2"). If both criteria are met I need to then show the text64000 field ("field3") in html format. If both criteria are NOT met I need it to  show nothing. 

The below code works to check "field1" and "field2" and then show a value in the span, either a typed in text value or a normal text field for that record. The problem is when I try to use the field that contains the html markup ("field3" in this example). It doesn't show anything (is blank). I know the "if" statement is working because I've tested it with other fields, just showing the field in html is the problem. Does anyone know how to tweak this so "field3" will show in html? I tried putting it in a div instead fo a span but that didn't work either.  Any help would be greatly appreciated. 

<div id="mydiv[@field:MyRecordUniqueID]"></div>

<SCRIPT LANGUAGE="JavaScript">

if (("[@field:myfield1]" == "SHOW") && ("[@field:myfield2]" == "active"))
{
document.getElementById("mydiv[@field:MyRecordUniqueID]").innerHTML ="<span>[@field:myfield3!]</span>";
} 

</script>

 

Share this post


Link to post
Share on other sites

1)Make sure HTML editor is turned off. Advanced setting. It can cause creating unproper ASCI symbols.

2) Paste the Code

<div id='mydiv[@field:MyRecordUniqueID]'></div>
 <script type="text/javascript"> 
 document.addEventListener('DataPageReady', function (event) {
    if (("[@field:myfield1]" == "SHOW") && ("[@field:myfield2]" == "active")) { 
        document.querySelector("#mydiv[@field:MyRecordUniqueID]").innerHTML =`<div>[@field:myfield3!]</div>`;
    }
}); 
 </script>

 

Share this post


Link to post
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...