Forum Moderators: open

Message Too Old, No Replies

Why is javascript not working correctly in Firefox

         

rkoya

5:29 pm on Nov 14, 2005 (gmt 0)



Hi,

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?

Section_8

4:14 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Good day rkoya. It could be because Firefox uses "nodes" or "Childe windows". And when you declare something via script, FireFox must know which window to target.

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.... :(

Fotiman

4:26 pm on Nov 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe something like this instead:

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);
}
}

Section_8

7:16 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Hey good idea. Just pop that in a variable maybe then FireFox won't misplace the data :D Good thinking!

Fotiman

7:50 pm on Nov 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




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.