Reputation: 3092
I am dynamically setting the values for a select box using java script
var dropDwnObj = document.getElementById("workingBranchCodeId");
dropDwnObj.options.length = 0;
var anOption = document.createElement("OPTION");
dropDwnObj.options.add(anOption) ;
for(var i = 0; i < jsonResult.subLocationList.length; i++) {
var anOption = document.createElement("OPTION");
dropDwnObj.options.add(anOption) ;
if(selValue == jsonResult.subLocationList[i].displayKey) {
anOption.innerHTML = jsonResult.subLocationList[i].displayValue;
anOption.value = jsonResult.subLocationList[i].displayKey;
}
}
How can I make this value as the selected value for the select box? currently it is coming like an option but i want this option to be the selected one for the select box
Upvotes: 1
Views: 44
Reputation: 825
Please set select box as multiple selection using multiple attriute like below
<select multiple>
</select>
and set selected attribute is true for options like below
anOption.selected = true;
Hope this will help you.
Upvotes: 1