Forum Moderators: open
I am having trouble with Javascript not being displayed in Firefox but displays fine in IE. This is the javascript code I am trying to get to work:
function populateDestination (destdisplist, destvallist) {
document.details.area.length=1;
var newElem;
var selectedItem = 0;
for (var i = 0; i < destdisplist.length; i++) {
newElem = document.createElement("OPTION");
newElem.value = destvallist[i];
newElem.text = destdisplist[i];
document.details.area.add(newElem);
if(newElem.value=="107") {selectedItem = i + 1;}
}
if (selectedItem!= 0)
{
document.details.area.options[selectedItem].selected = true;
listoffices(document.details.area.options[selectedItem].value);
}
}
Can anyone help?
I'm afraid I can't offer much for a solution. Though I recall something about (/*Node*/ root) declared next to the function name.... not sure rkoya.... :(
function populateDestination (destdisplist, destvallist) {
var areaOptions = document.details.area.options;
document.details.area.length=1;
var newElem;
var selectedItem = 0;
for (var i = 0; i < destdisplist.length; i++) {
newElem = new Option(destdisplist[i],destvallist[i]);
areaOptions[areaOptions.length] = newElem;
if(newElem.value=="107") {selectedItem = i + 1;}
}
if (selectedItem!= 0)
{
areaOptions[selectedItem].selected = true;
listoffices(areaOptions[selectedItem].value);
}
}
Hey good idea. Just pop that in a variable maybe then FireFox won't misplace the data :D Good thinking!
Actually, the difference is that this creates a new Option object vs. creating an element in the DOM. I think I read somewhere that trying to add options via the DOM doesn't work, but the new Option approach should.