Search
Other Sourcerer questions
Forum

Uncaught ReferenceError: getDance is not defined at HTMLButtonElement.onclick

Michael Barraclough's Avatar Michael Barraclough
If you click the Accept button at michaelbarraclough.uk/test#download the Accept and Reject buttons should disappear and a Download button should appear. Neither thing happens.

The console says: Uncaught ReferenceError: getDance is not defined
at HTMLButtonElement.onclick (VM226313 test:1:1)

The javascript function is added via Sourcerer and you can see it in the page source (part of <HEAD>. but same issue if I put it at the end of the <HTML> section
<script> 
function getDance() { 
 document.getElementById("yesNo").style.display = "none"; 
 document.getElementById("getPDF").style.display = "block"; 
} 
</script>
You can also see the onclick () is present in the page source
<div id="yesNo" style="text-align: center;"><button id="accept" class="mab-button green" onclick="getDance()">Accept</button> <button id="reject" class="mab-button red">Reject</button></div>
<div id="getPDF"><a href="/images/mabDownload/Addington Tunnel Dance.pdf" class="mab-button" style="display: none;" download=""> Download </a></div>

The code logic works fine when I use the W3Schools Try-It Editor.

What am I doing wrong, please?
Peter van Westen's Avatar Peter van Westen ADMIN
You now have a <script> tag inside a <script> tag. Not sure how you are adding this script via Sourcerer, but you are not doing it correctly.

Please read the documentation:
docs4.regularlabs.com/sourcerer/the-basi...tyles-and-javascript
Please post a rating at the Joomla! Extensions Directory
Michael Barraclough's Avatar Michael Barraclough
Thank you. I had not appreciated that I did not need to include the <script> ... < /script> tags when I added the function via Sourcerer. I have removed these and the JavaScript function is now being found (sadly, not working, but that is a different issue to be solved). Thank you for the prompt and helpful support.
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription