How to select an dropdown option via javascript?


Topic: How to select an dropdown option via javascript?

salmanfazal01 pro asked 7 days ago

How do I dynamically change the option from a select dropdown using javascript or jquery?

My html code:

<select class="mdb-select md-form" id="symbol" searchable="Search here..">
    <option value="ABC">ABC</option>
    <option value="XYZ">XYZ</option>
    <option value="SDA">SDA</option>
</select>

This is what I have tried till now:

$('select[id="symbol"] li:contains("XYZ")').trigger('click');

Piotr Obrebski staff answered 6 days ago

Hi salmanfaxal01,

I creaded simple snippet with solution to your request:

https://mdbootstrap.com/snippets/jquery/pjoter-2-0/805251

If you need additional help I am here for you.

Best Regards, Piotr


Please insert min. 20 characters.
Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: jQuery
  • MDB Version: 4.8.2
  • Device: Chrome
  • Browser: Chrome
  • OS: Chrome
  • Provided sample code: No
  • Provided link: No