1// Fast javascript function to clear all the options in an HTML select element
2// Provide the id of the select element
3// References to the old <select> object will become invalidated!
4// This function returns a reference to the new select object.
5function ClearOptionsFast(id)
6{
7 var selectObj = document.getElementById(id);
8 var selectParentNode = selectObj.parentNode;
9 var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy
10 selectParentNode.replaceChild(newSelectObj, selectObj);
11 return newSelectObj;
12}
13
14// This is an alternative, simpler method. Thanks to Victor T.
15// It does not appear to be as fast as the ClearOptionsFast method in FF 3.6.
16function ClearOptionsFastAlt(id)
17{
18 document.getElementById(id).innerHTML = "";
19}
20
21