How can I set the default selected index of select tag using java script? My code working well, but I can't determine the default selected value (for example) the first value.
var CompanySelect = document.getElementById("ManagingCompaniesSelect");
if (result && result.length > 0) {
CompanySelect.options[CompanySelect.options.length] = new Option(_seletCompany, -1);
for (var i = 0; i <= result.length-1; i++)
{ CompanySelect.options[CompanySelect.options.length] = new Option(result[i].ManagingCompanyName, result[i].MangingCompanyGUId); }
}
var txtManagingCompany = '#ManagingCompaniesSelect' + ' option[value=-1]';
$(txtManagingCompany).attr("selected", "selected");