How can i dynamically remove all options of a drop down box in javascript?
The fastest solution I was able to find is the following code (taken from this article):
// Fast javascript function to clear all the options in an HTML select element // Provide the id of the select element // References to the old object will become invalidated! // This function returns a reference to the new select object. function ClearOptionsFast(id) { var selectObj = document.getElementById(id); var selectParentNode = selectObj.parentNode; var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy selectParentNode.replaceChild(newSelectObj, selectObj); return newSelectObj; }