Reputation:
In safari 4 and all explorer browsers, whenever I try to call a function inside a javascript file which contains this function below, that first function isn't called.
So calling function1 will not work if function2 is inside the same .js file, explanation?
Here is the code which makes the problem. Whenever I remove this function, everything works fine and all functions work fine. So this function is causing a problem.
function addOption(selectbox, value, text, class, id_nr )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
optn.id = value;
if (class==1){ optn.className = "nav_option_main"; }
selectbox.options.add(optn);
}
Any ideas why?
Thanks
Upvotes: 0
Views: 227
Reputation: 2541
Maybe it gets upset because you use a reserved word (class
) as a variable identifier. Try using klazz or something else.
Here is a link to a list of reserved words: en.wikibooks.org/wiki/JavaScript/Reserved_Words
And here's some words from Monsieur Crockford (scroll down or search for the phrase "JavaScript is very heavy handed in its restrictions on reserved words"): crockford.com :)
Upvotes: 5
Reputation:
Problems I noticed:
1) class is a reserved word. Do not use it as a variable.
2) I cannot see your other function, so I am going to presume you have some implied globals and namespace collisions.
3) I cannot see what this function is doing, so I will assume it outputs an action that is in conflict with your prior function.
Upvotes: 2