OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

im trying to run some very basic javascript on a click event and im getting an undefined function error

  • Thread starter Thread starter bestbuilder04 bob
  • Start date Start date
B

bestbuilder04 bob

Guest
Code:
<script>
  function x() {
    console.log("thisWorks")
  }
</script>
<button onclick="x()"></button>

my hopes were that clicking the button would trigger the console command and i could add more code, but when i click it i get an error that looks like this error message im using opera GX browser about:blank page.

I checked w3schools and copied directly from their page, where it worked, i still got the error. (https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick) i tried moving the functions before the button element, i tried putting the script in the parent element of the button, i tried copying from the html in the w3schools page and it's the same error.

honestly im a very novice coder and it's probably something stupid but i would appreciate some help

edit: i asked a friend to do the same thing on their computer with the same result, so it's not my pc.

i have no clue why this works in the stack overflow preview but not in about:blank
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><script>
function x() {
console.log("thisWorks")
}
</script>
<button onclick="x()"></button></code></pre>
</div>
</div>
</p>
<p>my hopes were that clicking the button would trigger the console command and i could add more code, but when i click it i get an error that looks like this <a href="https://i.sstatic.net/Z4seGCem.png" rel="nofollow noreferrer">error message</a>
im using opera GX browser about:blank page.</p>
<p>I checked w3schools and copied directly from their page, where it worked, i still got the error. (<a href="https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick" rel="nofollow noreferrer">https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick</a>)
i tried moving the functions before the button element, i tried putting the script in the parent element of the button, i tried copying from the html in the w3schools page and it's the same error.</p>
<p>honestly im a very novice coder and it's probably something stupid but i would appreciate some help</p>
<p>edit: i asked a friend to do the same thing on their computer with the same result, so it's not my pc.</p>
<p>i have no clue why this works in the stack overflow preview but not in about:blank</p>
Continue reading...
 
Top