Change value of materialize select box by jquery Change value of materialize select box by jquery javascript javascript

Change value of materialize select box by jquery


It appears to work fine for me, changing the first drop down, resets the value of the second drop down to 1.

I have done a rough implementation on jsFiddle: http://jsfiddle.net/55r8fgxy/1/

<select id="select1">    <option value="1">1</option>    <option value="2">2</option>    <option value="3">3</option>    <option value="4">4</option>    <option value="5">5</option></select><select id="myselect">        <option value="1">1</option>    <option value="2">2</option>    <option value="3">3</option>    <option value="4">4</option>    <option value="5">5</option></select>

JS:

$(function() {    $("#select1").on('change', function() {        $('#myselect').val("1");        // re-initialize material-select        $('#myselect').material_select();    });});


$('#myselect').formSelect() ;

The new method is formSelect(), use this after you have updated the select.


As suggested by @logikal, you have got to re-Initialize

$("#myselect").material_select()