Topic: MaterialSelect Selecting an Option.

Thomas Emmanuel free asked 5 years ago


Expected behavior

Update the selected option dynamically.

Actual behavior

    <select id="country" class="mdb-select">
        <option value="" disabled selected>Select</option>
        <option value="ind">India</option>
        <option value="usa">America</option>
        <option value="myr">Malaysia</option>
    </select>

By Default "Select" is selected.In my application there is customer search field, if the customer is from Malaysia, i have to update the country dropdown with the customer's country.

Before updating to 4.8.10 i was using 4.7.7

$('#country').val('myr');

This was working fine.

But after 4.8.10. this doesn't work anymore. any alternative method to select an option?

Regards


poomkawin free answered 5 years ago


Hi,

Replace
$('#country').val('myr');
with
$('#country option[value="myr"]').attr('selected', true);
should solve your issue.

Here's an example: https://mdbootstrap.com/snippets/jquery/poomkawin/1218574


Thomas Emmanuel free commented 5 years ago

Thanks mate :) worked perfect!



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Resolved

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.10
  • Device: Lenovo, Mac
  • Browser: Chrome, Firefox
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No