I’ve read several questions about using a variable in multiple functions by making it global (defining it outside of a funciton)… however, I have a function that produces a dynamic value on click (gets an href value of a link) –
I need to pass that resulting variable into another function.
Basically, I’m grabbing a clicked link’s href value and then wanting to pass it to Ajax if a confirmation box is selected.
It doesn’t seem that declaring the variable globally would work, as it’s definition comes only if an onclick event is triggered.
Any thoughts?
You can create the variable as a global with a value of
null, and then set it in your first function. After you read the variable in your second function, set the value back tonull.Example: