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

210
Views
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 answers
Answer question

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 Report
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!