js автовыбор опции селекта после рефреша страницы

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
// get параметр filter_campaign
var filter_campaign = getParameterByName('filter_campaign')
if(filter_campaign != ''){
        // опции селекта filter_campaign
	var opts = document.getElementsByName("filter_campaign")[0].getElementsByTagName('option');
	var opts2 = Array.from(opts)
	opts2.forEach(function(item){
	    if(item.value == filter_campaign){
	    	item.setAttribute('selected', true)
	    }
	})
}

Leave a comment

Your email address will not be published.


*