Friday, March 27, 2009

Insert New option in select tag in JS

var theSelectList = $('theBigFatSelectList');
var myNewOption = new Option("My Option", "123");

theSelectList.selectedIndex =
InsertNewOption(myNewOption, theSelectList);

function InsertNewOption(newOption, selectElement)
{
var optsLen = selectElement.options.length;
selectElement.options[optsLen] = newOption;

return optsLen;
}

No comments:

Post a Comment