In the below code, if the current drop-down value points to the value available in listvalues variable, then the drop-down selected value should be changed into 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 have tried this:
$("#dk_container_selectForMonth").val($("#dk_container_selectForMonth li:first").val());
but it does 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?
Sorry for answering my question. The answer may helps to someone.
By refreshing the drop-down using jquery dropkick() method, the drop-down gets refreshed and first value gets assigned.
$('#selectForMonth').dropkick('refresh');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With