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

213
Vistas
How to pass a argument from one function to the another function onclick in javascript

I want to pass an argument onclick from one function to the another function

Suppose,

Html

<button class='btn1' onclick='passvalue(2)'>
<button class='btn2' onclick='getvalue()'>

when I will click on btn1, 2 value will pass from passvalue() to getvalue(). And then, Whenever i will click on btn2 only, getvalue() will print 2 on console.

But I couldn't able to do it.I hope my problem is enough clear to understand. Please someone help me to do that.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think this is not the best solution, but it should work for you.

This for HTML

<button onclick="firstFunc(2)">first</button> 
<button onclick="secondFunc()">second</button>

And this for JS

let val

function firstFunc(x){
    val = x
}
function secondFunc(){
    console.log(val)
}

And here is it in JsFidle

about 4 years ago · Juan Pablo Isaza Denunciar
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