I have a JS function that replaces text inside a h2 and span. The JS function is run using OnClick.
This works in all cases, but NOT when I change the value to what is pulled from an Advanced Custom Field in Wordpress.
Whenever the code is changed to the_field('content');
or get_field('content');
in a variable, it throws up the error SyntaxError: unexpected EOF
.
The Field is a basic text field, that currently outputs:
<p>test8</p>
It is being pulled in correctly in the html if I check the source.
The code:
<script type="text/javascript">
function ReplaceHeader(id,content) {
var container = document.getElementById(id);
container.innerHTML = content;
}
</script>
<?php $artist = get_field('artists_content'); ?>
<a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<?php echo $artist;?>')">
<path class="st3" d="M383.5,238.6c3.8,0,6.8-3.1,6.8-6.8s-3.1-6.8-6.8-6.8c-3.8,0-6.8,3.1-6.8,6.8l0,0
C376.6,235.5,379.7,238.6,383.5,238.6"/>
<text transform="matrix(1 0 0 1 398.2288 235.1945)" class="st3 st4 st5">ARTISTS</text>
</a>
This works:
<a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<p>Test8</p>')">
and even this works:
<?php $artist = '<p>Test8</p>' ?>
<a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<?php echo $artist;?>')">
But this doesn't:
<?php $artist = get_field('artists_content'); ?>
<a href="" onclick="ReplaceHeader('header','Artists'); ReplaceHeader('content','<?php echo $artist;?>')">