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.
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