Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Javascript function not working when called in HTML button. But when I simply run the code of the function on it's own, it works

I'm working on a project where I have written quite a few functions. When I run just the code that's in them (no function) it works. But when I plug the code into a function and call that function from an HTML button. It throws an error.

Here is the code for my button:

<button id="send" onclick="generateKeyPair()">Generate Random Key Pair</button>

And here is the code for the generateKeyPair() function:

                function generateKeyPair() {
                    var keyPair = web3.eth.accounts.create();
                    document.getElementById('privateKey').innerHTML = keyPair.privateKey;
                    document.getElementById('generatedAddress').innerHTML = keyPair.address;
                }

Finally, here is the error

Uncaught ReferenceError: generateKeyPair is not defined
at HTMLButtonElement.onclick

If this is in anyway helpful, I am using some packages, but all things I have used fine before.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!