Jump to content

Filling Combo on FireFox


RogerInHawaii

Recommended Posts

I've got a short function that fills up the selections of a combo box.

function FillComboSelections(controlId, selections){		//  selections is an array of text strings, one for each selection to be added to the combo box.	var control = document.getElementById(controlId);	control.length = 0; // To empty it of prior selections?	for (var index = 0; index < selections.length; ++index)	{		var element=document.createElement('option');		element.text=selections[index];		control.add(element);  // THIS FAILS with FireFox Browser	}

It works fine on several browsers, but when it gets to the control.add(element) instruction it fails when using the Firefox browser. It does not add the element and it doesn't even continue on in the loop.Does anyone have any idea why this fails? Or how I might re-write it so that it will work on Firefox?

Link to comment
Share on other sites

As you can see here, the W3C Standard version of the .add method requires two arguments. So Firefox is correct. Other browsers may accommodate the IE variation. The try-catch technique demonstrated on the page I linked you to is cross-browser compatible.

Link to comment
Share on other sites

As you can see here, the W3C Standard version of the .add method requires two arguments. So Firefox is correct. Other browsers may accommodate the IE variation. The try-catch technique demonstrated on the page I linked you to is cross-browser compatible.
Excellent. Thank you. That works perfectly.I had come across some sample code for adding combo box entries and it only included the option field, not the before field.Oh for the day when all the browser companies get together and agree to conform to the standards so we don't have to handle all these exception cases.
Link to comment
Share on other sites

Oh for the day when all the browser companies get together and agree to conform to the standards so we don't have to handle all these exception cases.
But then there would be no point in having different browsers, other than different interfaces. :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...