how to change select item from drop-down menu by JavaScript
<select name="example_length" aria-controls="example" class="">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
I tried to change value of drop-down menu by:
document.getElementsByName("example_length")[0].value=100
but number only cahanged in HTML but content not changed ;
link to example Table Sorting
i found answer
by plain JavaScript
document.getElementsByName("example_length")[0].value = 50;
var event = new Event('change');
document.getElementsByName("example_length")[0].dispatchEvent(event);
by jQuery
$( "select[name='example_length']" ).val(50).change();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.