The reset dropdown value for the first value when the condition is met

In the code below, if the current drop-down value indicates the value available in the listvalues ​​variable, the drop-down selected value should be changed to the first value.

if (selectedForYear() == 2016) { var d = new Date(); var month = d.getMonth(); month = month + 3; while (month <= 13) { $('#dk_container_selectForMonth .dk_options li:nth-child(' + month + ')').css({ "display": 'none' }); var listvalues = $('#dk_container_selectForMonth .dk_options li:nth-child(' + month + ')').text(); if ($('#dk_container_selectForMonth .dk_options li.dk_option_current a').text() == listvalues) { $("#dk_container_selectForMonth").val($("#dk_container_selectForMonth li:first").val()); } month++; } } 

I tried this:

 $("#dk_container_selectForMonth").val($("#dk_container_selectForMonth li:first").val()); 

but that will not work.

Here is the HTML:

 <div class="flexContainer mediumGutter"> <div class="flexContent"> <select data-bind="options: month, optionsCaption: 'Month', value: selectedForMonth" id="selectForMonth" tabindex="8" style="width: 130px"> <option>month</option> </select> </div> <div class="flexContent"> <select data-bind="options: year, optionsCaption: 'Year', value: selectedForYear" id="selectForYear" tabindex="9" style="width: 130px"> <option>year</option> </select> </div> 

Is there any way to do this?

+5
source share
1 answer

Sorry for the answer to my question. The answer may help someone.

By updating the drop-down list with the jquery dropkick () method, the drop-down list is updated and gets the first value.

 $('#selectForMonth').dropkick('refresh'); 
+2
source

Source: https://habr.com/ru/post/1246042/


All Articles