I am trying to add a javascript via a Custom HTML tag in Google Tag Manager in order to add details to hidden fields in Gravity Forms.
Here is a screenshot of the error I am getting and as a result, the workspace can't be saved:
Any suggestions for how to get it to validate?
<script>
if (document.getElementById("input_2_29)){
document.getElementById("input_2_29").value = "{{JS - GA Medium}}";
document.getElementById("input_2_30").value = "{{JS - GA Source}}";
document.getElementById("input_2_31").value = "{{JS - GA Campaign}}";
document.getElementById("input_2_32").value = "{{JS - GA Keyword}}";
document.getElementById("input_2_33").value = "{{JS - GA Content}}";
}
</script>
It happend because you didn't close the string argument of getElementById
function in the second line.
Update your code like this and it should fix the problem:
<script>
if (document.getElementById("input_2_29")){
document.getElementById("input_2_29").value = "{{JS - GA Medium}}";
document.getElementById("input_2_30").value = "{{JS - GA Source}}";
document.getElementById("input_2_31").value = "{{JS - GA Campaign}}";
document.getElementById("input_2_32").value = "{{JS - GA Keyword}}";
document.getElementById("input_2_33").value = "{{JS - GA Content}}";
}
</script>