When you're in a situation to add the new items to the HTML drop down element or list box i.e.; if you would like to add a drop down value based on the AJAX operation that user has made, the below Javascript will be handy for you to add them dynamically.


//Common function to add a new item to the drop down or list box
function addElement(element, name, value)
{
if(document.getElementById(element))
{
document.getElementById(element).options[document.getElementById(element).options.length]=new Option(name,value);
}
}
The above Javascript function addElement will accept three arguments element, name, and value. You should pass the drop down or list box id as the element, name and value of the new option to be included as part of the element. Please note that I've tested this on all the browsers IE 6.0,7.0, Mozilla 2.0,3.0 and Google chrome. If you've sometime, why don't you read my other Javascript articles/programs