Passing function-specific variables

Posted by Simon Carlson on Stack Overflow See other posts from Stack Overflow or by Simon Carlson
Published on 2012-11-10T15:25:56Z Indexed on 2012/11/10 17:00 UTC
Read the original article Hit count: 148

Filed under:
|
|

Say I got two functions that looks like this:

function main(Index)
{
    doStuff();
}

function doStuff()
{
    if(Index == 1)
    {
        document.write("Hello world!")
    }
}

And some HTML:

<input type="button" value="Click me" onclick="main(1)" />

I realize this is a very stupid way to use function-specific variables and such, but it's just out of curiosity. So is it possible to pass the variable Index from the main function to the doStuff function?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery