onclick Can't find variable: userInput code example
Example: html onclick can't find function
<!--
Your script is most likely after your HTML.
Include it before html, so that your function is defined.
Another reason your function may be undefined is beacuse there is
some kind of error blocking your function from exectuing!
-->
<script>
function BtnPress() {
console.log("I work because i am defined before my caller!");
}
</script>
<button onclick="BtnPress()">Press Me!</button>