Reputation: 409
I am passing string to a function but its giving me an error :
assignAttr(var menu="menu", var container="menu_container",var text="menu_text");
function assignAttr(menu,container,text)
{
alert(menu + container + text);
}
Upvotes: 0
Views: 149
Reputation: 3318
You can not declare the variables like this. You need to do it like:
var menu="menu";
var container="menu_container";
var text="menu_text";
assignAttr(menu, container, text);
function assignAttr(menu,container,text)
{
alert(menu + container + text);
}
Upvotes: 0
Reputation: 70701
You simply need to call the function like this:
assignAttr("menu", "menu_container", "menu_text");
Upvotes: 4
Reputation: 28648
Proper code is like this:
function assignAttr(menu,container,text) {
alert(menu + container + text);
}
var menu="menu";
var container="menu_container";
var text="menu_text";
assignAttr(menu, container, text);
The code serves the purpose of display how to use a variable as a parameter.
And of course you can write function call as:
assignAttr("menu", "menu_container", "menu_text");
Upvotes: 2