I have this code: <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <script language="javascript" > function outer(data) { var operand1 = data; function inner(operand2) { alert(operand1 + operand2) } } </script> <body> //<input type="button" value="1" onclick="outer(3)(2)" /> //<input type="button" value="2" onclick="outer(3)(2)" /> <div id="target"></div> </body> </html> Code (markup): How do I call the inner function and pass operand?
I do apologise if I don't understand but you seem to be mixing a few things up here. If you want to call the function inner then define inner as a non-nested function OR call outer and have outer call inner. Also in your onClick event handler you have outer(3)(2). I don't believe you can do that. It should be outer(3,2). You will possibly need to redefine outer to accept two parameters. I may be totally off base but that is how I 'THINK' you want it to work
I agree with datropics. If you want to create two functions, you should implement them separately. However, if you wanted to create a function whose code was dependent on some variable, for example, use this syntax: var f_someFunction = function(s_parameterOne, obj_parameterTwo ...) { /* Function code... or an eval statement goes here. */ }; Code (markup):