-6

I want to call function from variable i got success but i want to call function and also pass parameters,how to do it. please let me know.

Below i have mention function which is working without parameter.

function myfunction(){
alert("hellow world");
} 

var aa= "myfunction";  
window[aa]();   // working 


function myfunction(param){
alert(param);
}

// .....?
Syed Daniyal Asif
  • 726
  • 1
  • 5
  • 19
  • 1
    @Cerbrus The answer in the question of which you marked this a duplicate is what the OP says he can do already. So while this is a very poor question (OP should have at least tried the obvious), I don't think it's a duplicate of the question that you selected, as that question (and its marked answer) do not address passing parameters. – Patrick Q Nov 05 '14 at 14:12

4 Answers4

2

You can pass arguments to your function where you call window[aa]() like so:

function myfunction(text){
    alert(text);
} 

var aa= "myfunction";  
window[aa]("Hello Again..."); // just put any arguments in the parentheses.
Chris
  • 3,328
  • 1
  • 32
  • 40
1

Just pass it in:

window[aa](param)
tymeJV
  • 103,943
  • 14
  • 161
  • 157
1

Can you just put the parameter between the parentheses when you call the function?

window[aa]("Hello, world");
B W
  • 692
  • 1
  • 8
  • 21
1

use this:

 function myfunction(param){
    alert(param);
 }

    var aa= "myfunction";  
    window[aa]('mk');
Mukund Kumar
  • 21,413
  • 18
  • 59
  • 79