Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery change select value not working

Tags:

html

jquery

I'm trying to set the select option with jquery but it's not working properly. It actually set the value but the text is not updated.

I have tried with .prop('selected',true), .attr('selected',true), .prop('selected','selected'), .val() and .val().change() but nothig seems to work

Here is the select

<select class="input-field" id="equip_type" name="equip_type">
    <option value="" disabled selected>Tipo de Equipo </option> 
    <option value="0">equip_type_other</option>
    <option value="1">equip_type_desktop</option>
    <option value="2">equip_type_laptop</option>
    <option value="3">equip_type_tablet</option>
    <option value="4">equip_type_printer</option>
</select>

I'm going to set the option within an ajax function, so the value came from the function. This is what I'm currently trying

$('#equip_type').val(data.equipType).change();

I have use the same method with other forms, but just this one is causing this truble. Is there something I'm missing?

like image 481
Carlos Schuldiner Avatar asked Mar 24 '26 05:03

Carlos Schuldiner


1 Answers

$('#equip_type').val(data.equipType).trigger('change');
like image 67
Artem Gorlachev Avatar answered Mar 25 '26 20:03

Artem Gorlachev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!