-1

how to select the option with the value we give using document.getElementById("id"):

document.getElementById("dropdownlist").selectedValue="apple";

or change the text of a control with the help of this in javascript code.

i am filling the dropdown like this:

 <select id="ddlC" class="form-control" ng-model="mdlC" runat="server" style="width: 250px" ng-options="c.CId as c.Na for c in Cat">
                <option value="">Select Category</option>
            </select>
BKM
  • 186
  • 2
  • 15

3 Answers3

2

Change selectedValue to value

document.getElementById("dropdownlist").value = "apple";
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
sibabrat swain
  • 1,277
  • 8
  • 20
1

Try this

    var element = document.getElementById("dropdownlist");
    element.value = "apple";
Hack Dawg
  • 108
  • 9
1

Take a look at this one too

Through document.getElementById("dropdownlist").value = "option3"; you can set a specific option to be selected

var dropDownOptions = ["option1", "option2", "option3", "others"]
 var options = "";
 
for (option in dropDownOptions) {
    options += "<option>" + dropDownOptions[option] + "</option>";
}
document.getElementById("dropdownlist").innerHTML = options;

// select option by value
document.getElementById("dropdownlist").value = "option3";
<select name="category" id="dropdownlist"/>
Mara Black
  • 1,666
  • 18
  • 23