Aman
Aman

Reputation: 1455

How to clear dropdownlist contorl in Javascript

Please help how to clear dropdownlist control in Javascript

Upvotes: 2

Views: 9035

Answers (3)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

document.getElementById('idofselectbox').options.length = 0;

Upvotes: 8

RPM1984
RPM1984

Reputation: 73112

function RemoveItems()
{
   var objDrpList = document.getElementById ('theIdOfYourDdl');

   for(i=objDrpList.length-1; i>=0; i--)
   {
      if(objDrpList.options[i].selected)
      {
         objDrpList.options[i] = null;
      }
   }
}

EDIT:

Darin's answer is actually the way to go. Both work, but less code is better.

Upvotes: 0

Umair A.
Umair A.

Reputation: 6873

Simply remove its child elements which are <option>

Upvotes: 0

Related Questions