I am down on this. i cant figure out how i can use a variable argument passed to a function to access a DOM element.
here is what i was trying to do
function resetField(fieldName){
document.forms[1].fieldName.options.length = null;
var option = new Option();
option.value = "";
option.text = "--Select a "+fieldName.toUpperCase()+"--";
document.forms[1].level.options[0] = option;
}
Call the above function like so
resetField('course');
the problem is in the function argument "fieldName" javascript says:
"document.forms[1].fieldName is undefined "
javascript is trying to read the fieldName variable as if it is not a variable because from firebug when you hover over the it, shows its == to the string in the function call but inside the function it says its undefined.
what can i over come this problem thank you.