Fill Dropdownlist from Javascript
Hi, today we will learn how to fill Dropdownlist from Javascript here is how:-
function fill_dropdown_list()
{
var main_ddl = document.getElementsById('<%=dropdownlist1.ClientId%>');
var options = document.createElement('option');
for(var i=1;i<=10;i++)
{
if(options!=null)
{
options.text = "Hello"+i;
options.value = i;
if(main_ddl!=null)
main_ddl.options.add(options);
}
}
}
<asp:Button id="btn_fill_drpdown" Text="Fill Dropdown" runat="server" onClientClick = "fill_dropdown_list();"></asp:Button>