I have a DWT TBB having code something like that -
<!-- TemplateBeginRepeat name="Video_Array" -->
<li>
<!-- TemplateBeginIf cond="Component.Schema == 'Video Collection'" -->
<a onclick="_gaq.push(['_trackEvent', 'XYZ', 'ABC', '@@List${TemplateRepeatIndex}.Fields.title@@']);" href="@@List${TemplateRepeatIndex}.Fields.link@@" target="_blank">
@@List${TemplateRepeatIndex}.Fields.title@@
</a>
<!-- TemplateEndIf -->
</li>
<!-- TemplateEndRepeat -->
Now here Single quote in the title of the Video component creates a problem to execute the java script applied on the onclick event. So i have to escapee this anyhow. It looks something like below in the page source –
onclick="_gaq.push(['_trackEvent', 'Video Collection', 'Click', 'Music and fun daddy's child']);">
There are few challenges for me to go ahead for the fix -
- I cannot ask editors to avoid this character or place HTML entity ' in place of this.
- I cannot write Custom function to replace it something like Replace("'", "\'") with in the DWT.
- I can't blindly replace "'" with "\'" as it will make our content incorrect some places.
The only way , i can think to write a java script function and call it with in the java script function called on onclick.
I am not good in java script so could somebody help me to sort it out through java script.
Is there any other way in Tridion to do same in my circumstances ?