Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda