Material Select Set selected value


Topic: Material Select Set selected value

hetal asked 8 years ago

I have Material Select List and I want to set selected value by using javascript or JQuery but material select list not showing that value

Michal Szymanski staff pro premium priority answered 8 years ago

Can you provide your sample code?

dejan.mauer pro answered 8 years ago

I am struggling with the same problem... I have this HTML:
<div class="col-md-4 input-field">
	<select id="selectDiscount">
		<option id="selectDiscountNone" selected value="None">Not specified</option>
		<option id="selectDiscountMoney" value="Money">in money</option>
		<option id="selectDiscountPercent"value="Percent">in percent</option>
	</select>
</div>
How it is possible to select, for example, second option as with JavaScript?

Bartłomiej Malanowski staff pro premium answered 8 years ago

It's possible. Here you can find a solution

dejan.mauer pro answered 8 years ago

Great! This solved my issue.

var element = $("#youselectId")

element.prevAll('.select-dropdown').children('li:eq(2)').trigger('click');

you can  remplace the number 2 with the item id that you want select

var changeSelectPickerValue = function (id, value) {

var element = $("#" +id)
element.prevAll('.select-dropdown').children('li:eq('+value+')').trigger('click');

}


Furey commented 7 years ago

$(#element_id)prevAll(‘.select-dropdown’).children(‘li:contains(‘+value+’)’).trigger(‘click’);

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No