Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda