Topic: Assign value to a select

pabloabl premium asked 3 years ago


I have the following select:

<select class="mdb-select md-form" id="tipo_edita" name="tipo_edita" searchable="Tipo de geocerca">
        <option value="A99" disabled selected>Tipo</option>
            <option value="1" data-secondary-text="uno" data-icon="1.png" >1</option>
    <option value="2" data-secondary-text="dos" data-icon="2.png" >2</option>
    <option value="3" data-secondary-text="tres" data-icon="3.png" >3</option>
    <option value="4" data-secondary-text="cuatro" data-icon="4.png" >4</option>

I want to assign a value (selected) with javascript. a normal select without MDB would do it like this:

JS: document.getElementById ('tipo_edita'). value = 2;

but in this case, with MDB, it doesn't work, does anyone know how to do it?

Thanks and best regards!. Pablo

Grzegorz Bujański staff commented 3 years ago

Hi. Try this: $('#tipo_edita').val(2)

pabloabl premium answered 3 years ago

thanks, it worked perfect!

Grzegorz Bujański staff commented 3 years ago

Great :) I'm glad I could help. Best, Grzegorz

Please insert min. 20 characters.


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



Specification of the issue

  • User: Premium
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.19.0
  • Device: PC
  • Browser: Chrome
  • OS: Win10
  • Provided sample code: No
  • Provided link: No