Topic: Assign value to a select
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
pabloabl pro premium answered 5 years ago
thanks, it worked perfect!
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Pro
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.19.0
- Device: PC
- Browser: Chrome
- OS: Win10
- Provided sample code: No
- Provided link: No
Grzegorz Bujański staff commented 5 years ago
Hi. Try this:
$('#tipo_edita').val(2)