Hi,
I have a function that creates and fills dropdown boxes. The function used to work fine when it was not embedded in a form. However, when I moved it into the form, I can no longer add my dynamically created OPTIONs.
I have a select statement making the dropdown box named locationCombo. This is what I had when the dropdown box was not in the form:
var theName = "locationCombo"
for (var j=0; j<currentNode.childNodes.length; j++)
{
var oOption = document.createElement("OPTION"
oOption.text = (currentNode.childNodes.item(j).text);
oOption.value = j;
(eval(theName)).options.add(oOption);
}
It is the last line that is giving me the grief. If I have to reference the form, I must change the last line to:
document.mainMenu.locationCombo.options.add(oOption);
However, I do not wish to have the 'locationCombo' hardcoded into the statement. I wish to use eval so that the names of the dropdown can be dynamic and this function can be generic. But, when I use the following I get an 'expected identifier' error.
document.mainMenu.(eval(theName)).options.add(oOption);
Why does eval seem to work outside of the form, but not inside the form? Is there anything else I can do to not have the names of boxes hardcoded?
Any help will be much appreciatted. Thanks is advance,
Draug
I have a function that creates and fills dropdown boxes. The function used to work fine when it was not embedded in a form. However, when I moved it into the form, I can no longer add my dynamically created OPTIONs.
I have a select statement making the dropdown box named locationCombo. This is what I had when the dropdown box was not in the form:
var theName = "locationCombo"
for (var j=0; j<currentNode.childNodes.length; j++)
{
var oOption = document.createElement("OPTION"
oOption.text = (currentNode.childNodes.item(j).text);
oOption.value = j;
(eval(theName)).options.add(oOption);
}
It is the last line that is giving me the grief. If I have to reference the form, I must change the last line to:
document.mainMenu.locationCombo.options.add(oOption);
However, I do not wish to have the 'locationCombo' hardcoded into the statement. I wish to use eval so that the names of the dropdown can be dynamic and this function can be generic. But, when I use the following I get an 'expected identifier' error.
document.mainMenu.(eval(theName)).options.add(oOption);
Why does eval seem to work outside of the form, but not inside the form? Is there anything else I can do to not have the names of boxes hardcoded?
Any help will be much appreciatted. Thanks is advance,
Draug