How to Bind Comma Separated Values into Dropdown using Javascript

Rajkumardotnet90
Posted by Rajkumardotnet90 under JavaScript category on | Points: 40 | Views : 5509
Var ddl=document.getElementById("ddl");

Document.ctrlform.ddl.options.Length=0; //for clearing all values in dropdown
//ctrlform is the Form id
Var str='<None>,first,second,third';
Var myarray=str.Split(,);
For(var i=0;i<myarray.Length;i++)
{

Var option=document.createElement("Option");
Option.text=myarray[i];
Option.value=myarray[i];
ddl.Options.Add(Option,i);
}

Comments or Responses

Login to post response