Alphabet
Alphabet

Reputation: 129

HTML dropdownlist

I have dropdown here and want to set the default value which is value="inventory". But not working well. Anyone know if I missing something? I have tried selected or selected="selected" but does not working. Thank you.

function item() {
  var x = document.getElementById("itemType").value;
  if (x == "P&L") {
    $("#ML").prop("checked", true);
  }
}
<!-- ITEM TYPE -->
<div class="k-edit-label">
  <label for="itemType">Item Type</label>
</div>
<select id="itemType" onchange="item()" style="width:60%; margin:5px 0px 5px 0px;" data-role="dropdownlist" data-bind="value: value">
  <option value="inventory" selected="selected">Inventory</option>
  <option value="P&L">P&L</option>
  <option value='assets'>Assets</option>
</select>

Upvotes: 2

Views: 77

Answers (2)

Hitech Hitesh
Hitech Hitesh

Reputation: 1635

Change the attribute selected like the below and the value to the Inventory because you are displaying the it as I capital so they are not matching this may even work sometime in chrome and Firefox sometimes but will not WORK in IE.

So change the value from "inventory" to "Inventory"

<option value="Inventory" selected>Inventory</option>

One more thing .value is not proper use . selected

document.getElementById("itemType").selected    

Upvotes: 0

Fahad Subzwari
Fahad Subzwari

Reputation: 2325

just use this <option value="inventory" selected>Inventory</option>

<select id="itemType" onchange="item()" style="width:60%; margin:5px 0px 5px 0px;" data-role="dropdownlist" data-bind="value: value">
  <option value="inventory" selected>Inventory</option>
  <option value="P&L">P&L</option>
  <option value='assets'>Assets</option>
</select>

Upvotes: 1

Related Questions