• Home
  • Frontend
  • JQuery loop for list of elements and change select value (bootstrap select)

JQuery loop for list of elements and change select value (bootstrap select)

linkaiyi
Follow

loop through jquery list of elements

$('.mdm-period-select').on('change', function() { // bind change function to all elements with class mdm-period-select
        var period = $(this).val();
        $('.mdm-period-select').each(function(i, obj) { //loop through the list of selected elements
            // console.log($(this))
            $(this).selectpicker('val', period) // set value of each select without trigger change event
        });
        if (period === 'YTD') {
            localforage.getItem('dataset_ytd').then(function(value) {
            window.dataset = value;
            reloadData()
            }).catch(function (error) {
                console.log(error)
            });
        } else if (period === 'MTD') {
            localforage.getItem('dataset_mtd').then(function(value) {
            window.dataset = value;
            reloadData()
            }).catch(function (error) {
                console.log(error)
            });
        } else {
            localforage.getItem('dataset_ttm').then(function(value) {
            window.dataset = value;
            reloadData()
            }).catch(function (error) {
                console.log(error)
            });
        }
    });
Object has 0 attachments

Was this article helpful?

This article is viewed 25 times!

Recent Viewed Articles

0 Comments

Leave a Comment

Support