Topic: Assign value to a select

pabloabl premium asked 2 years ago


Hello!!!!.

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>
  </select>

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 2 years ago

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


pabloabl premium answered 2 years ago


thanks, it worked perfect!


Grzegorz Bujański staff commented 2 years ago

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



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

  • 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