housamz
housamz

Reputation: 465

Javascript onClick function with parameters

I have a Javascript function as below:

function letMeGo(var1, var2, var3){
    if(var1 == 1 && var2 == 1 && var3 == 1){
        document.getElementById('goOn').href="goOn.php";
    }
}

the variables are the return of other functions.

And I need it to be triggered by:

<a id="goOn" onclick="letMeGo(var1, var2, var3)">Go On</a> 

it is not working unless I removed the variable in both, the link and the function. How can i get it to work with them?

Upvotes: 1

Views: 1154

Answers (1)

Sebas
Sebas

Reputation: 21522

you have to affect the return of the other functions to global variables (example: window.myvar1) and use them instead of your parameters var1, var2, var3.

I mean to not use any parameters in your function letMeGo and inside it, replace var1 by its global variable equivalent, and so on for var2 and var3.

Upvotes: 1

Related Questions