refresh select element after X seconds

时间:2016-05-17 11:05:20

标签: javascript jquery html

I am attempting to refresh a dropdown select after X seconds, currently the dropdown submits a form onChange. the browser prompts a download/save as alert. I would like the dropdown to return to value="0", after the first onChange/formsubmit.

<select class="selectpicker" id="csv_export" name="csv_export" onchange="this.form.submit()">

            <option value="0"
                    data-content="<i class='fa fa-cloud-download'></i><span class='hidden-sm'> Export as  </span>"></option>
            <option data-icon="fa fa-file-excel-o" style="background: #5cb85c; color: #fff;"
                    value="1"
                    data-content="<i class='fa fa-file-excel-o'></i><span class='hidden-sm'> CSV  </span>"></option>

   <script>
    $(document).ready(
            function() {
                setInterval(function() {

                    $('#csv_export').append('<option value="0"></option>');
                }, 3000);
            });
   </script>

2 个答案:

答案 0 :(得分:0)

If you want to simply set the select back to the first option you want

$('#csv_export').val('0');

not to append a new option which is what your code currently does.

答案 1 :(得分:0)

$(document).ready(
        function() {
            setInterval(function() {

                $('#csv_export').html('<option value="0">-select-</option>');
            }, 3000);
        });

this works