Populated JavaScript changing characters to character entities

112 Views Asked by At

I am using a CMS to host landing pages. Each of the landing pages begin with about 600 lines of JavaScript which is identical across landing pages. This script basically validates the form and adds in some conditional functionality. I am not the creator of the script and my knowledge of JavaScript is limited.

My initial goal was to remove the JS and place it into an external file and link to it via <script src="">, however, this does not work. I've worked with support on this and they said basically, "the CMS will not action on the script in the reference file."

My secondary option is to leave the standard <script type="text/JavaScript"></script> tags in the head section (embedded, not linked), cut the JS out from between and place into a field merge within the CMS, then populate that field merge between those tags. Everything populates, but the field merge is transitioning a few characters to their character entities, e.g.

< is &lt;
> is &gt;
& is &amp;
' is &39;
" is &quot;

Just those five are being converted and this is how my JS will populate into the landing page. Unfortunately it is breaking the functionality by doing so. A sample of what this looks like when populated in the landing page:

else if (args.Type == &#39;multisel&#39;) {<br />
var selCount = 0;<br />
for (var i = 0; i &lt; Element.length; i++) {<br />
if (Element[i].selected &amp;&amp; Element[i].value != &#39;&#39;) {<br />
selCount += 1;<br />

as you can see it is also adding those br tags, but I imagine I could simply minify to get rid of those.

I've researched adding an additional script below to convert these entities back into characters, though I have been unsuccessful so far. Is it even possible to add a subsequent script within the code or landing page that would reference the populated JS and convert the entities back into characters?

Places I've been and methods I've attempted thus far:
Convert special characters to HTML in Javascript
Unescape HTML entities in Javascript?
Encode html entities in javascript
HTML Entity Decode
http://developwithstyle.com/articles/2010/06/29/converting-html-entities-to-characters/
http://www.webdeveloper.com/forum/showthread.php?136026-RESOLVED-convert-HTML-Entities-into-normal-characters

0

There are 0 best solutions below