I’m creating a combo box which loads options from JSON..Its loading the menus as expected.But I need to display the text “Select the one” in the combo box by default. I tried but can’t find the solution..Can you advice me,How can i achieve it?
window.onload = function() {
var obj = JSON.parse(str);
for (var i=0; i < obj.MenuParentTabs.length; i++) {
var option = document.createElement("option");
option.innerHTML = obj.MenuParentTabs[i].parentTabName;
document.form1.fruits.appendChild(option);
}
}
You need to create the
optionwith the text you want, before theforloop:If the
optionisn’t the first child of theselect(i.e. you don’t put it before theforloop for some reason), also set theselectedattribute as well:Complete code to help the OP: