Как выбрать select при определенном url

Очень понадобилось осуществить такую автоматическую выборку определенного значения в селекте при определенном url... Понимаю что нужно начать вот с такого....

window.onload = function (){
alert(location.href);
if (location.href == "website.com/page1")
   {
     document.getElementsByTagName('имя селекта').options[14].selected=true;
   }
}

Но что то не работает..... Выдает ошибку:

common.js:118 Uncaught TypeError: Cannot read property '14' of undefined at window.onload (common.js:118)

Подскажите пожалуйста, что я делаю не так. Буду очень благодарен, спасибо.

Привожу часть HTML кода, весь код можно посмотреть по ссылке: http://udnlxdemo.ru/mebelmultimarka_wp/katalog/

<body class="archive category category-katalog category-5">
    <div id="wrapper">
        <div id="header-mobile" class="d-block d-lg-none">
            <div class="container py-2">
                <div class="row">
                    <div class="col-3 d-flex align-items-center">
                        <div class="mobile-menu-button"><hr><hr><hr></div>
                    </div>
                    <div class="col-9 text-right d-flex align-items-center justify-content-end"><a class="phone font-weight-bold" href="tel:+74955096396">+7 (495) 509 63 96</a></div>
                </div>
            </div>
            <div class="container">
                <div class="mobile-menu"><ul id="menu-main" class="menu"><li id="menu-item-87" class="menu-item menu-item-type-taxonomy menu-item-object-category current-menu-item menu-item-has-children menu-item-87"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/" aria-current="page">Каталог</a>
<ul class="sub-menu">
    <li id="menu-item-378" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-378"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/kuxni/">Кухни</a></li>
    <li id="menu-item-379" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-379"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/mebel/">Мебель</a></li>
    <li id="menu-item-387" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-387"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/svet/">Свет</a></li>
    <li id="menu-item-481" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-481"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/aksessuary/">Аксессуары</a></li>
    <li id="menu-item-482" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-482"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/dekor/">Декор</a></li>
    <li id="menu-item-480" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-480"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/drugoe/">Другое</a></li>
</ul>
</li>
<li id="menu-item-479" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-479"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/uslugi/">Услуги</a></li>
<li id="menu-item-526" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-526"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/gotovye-obekty/">Готовые объекты</a></li>
<li id="menu-item-85" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-85"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/o-kompanii/">О компании</a></li>
<li id="menu-item-84" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-84"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/dizajneram/">Дизайнерам</a></li>
<li id="menu-item-83" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-83"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/informaciya/">Информация</a></li>
<li id="menu-item-82" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-82"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/kontakty/">Контакты</a></li>
</ul></div>
            </div>
        </div>
        <div id="header-top">
            <div class="container">
                <div class="row justify-content-center align-items-center">
                    <div class="col-12 col-sm-5 col-lg-4 d-flex justify-content-center justify-content-sm-start">
                        <a href="/"><img src="http://udnlxdemo.ru/mebelmultimarka_wp/wp-content/themes/mebel/img/logo.png"></a>
                    </div>
                    <div class="col-12 col-sm-7 col-lg-5 d-flex justify-content-center justify-content-sm-end">
                        <div id="search-block">
                            <form action="http://udnlxdemo.ru/mebelmultimarka_wp" method="get" class="d-flex align-items-center">
                                <input type="text" name="s" class="search-input" placeholder="Поиск..." value="">
                                <button type="submit"><img src="http://udnlxdemo.ru/mebelmultimarka_wp/wp-content/themes/mebel/img/search.png" width="40"></button>
                            </form>
                        </div>
                    </div>
                    <div class="col-0 col-lg-3 d-flex align-items-center justify-content-end">
                        <a class="phone font-weight-bold d-none d-lg-block" href="tel:+74955096396">+7 (495) 509 63 96</a>
                    </div>
                </div>
            </div>
        </div>
        <div id="header-bottom" class="py-2 d-none d-lg-block w-100">
            <div class="container">
                <ul id="menu-main" class="menu"><li id="menu-item-87" class="menu-item menu-item-type-taxonomy menu-item-object-category current-menu-item menu-item-has-children menu-item-87"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/" aria-current="page">Каталог</a>
<ul class="sub-menu">
    <li id="menu-item-378" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-378"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/kuxni/">Кухни</a></li>
    <li id="menu-item-379" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-379"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/mebel/">Мебель</a></li>
    <li id="menu-item-387" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-387"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/svet/">Свет</a></li>
    <li id="menu-item-481" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-481"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/aksessuary/">Аксессуары</a></li>
    <li id="menu-item-482" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-482"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/dekor/">Декор</a></li>
    <li id="menu-item-480" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-480"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/drugoe/">Другое</a></li>
</ul>
</li>
<li id="menu-item-479" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-479"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/uslugi/">Услуги</a></li>
<li id="menu-item-526" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-526"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/gotovye-obekty/">Готовые объекты</a></li>
<li id="menu-item-85" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-85"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/o-kompanii/">О компании</a></li>
<li id="menu-item-84" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-84"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/dizajneram/">Дизайнерам</a></li>
<li id="menu-item-83" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-83"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/informaciya/">Информация</a></li>
<li id="menu-item-82" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-82"><a href="http://udnlxdemo.ru/mebelmultimarka_wp/kontakty/">Контакты</a></li>
</ul>           </div>
        </div>

<div class="category catalog">
    <div class="content-header">
        <div class="container">
            <h1 class="header font-weight-bold">Каталог</h1>
            <div class="breadcrumbs text-uppercase">
            <!-- Breadcrumb NavXT 6.5.0 -->
<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Перейти к Мебель." href="http://udnlxdemo.ru/mebelmultimarka_wp" class="home"><span property="name">Главная</span></a><meta property="position" content="1"></span> // <span property="itemListElement" typeof="ListItem"><span property="name" class="archive taxonomy category current-item">Каталог</span><meta property="url" content="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/"><meta property="position" content="2"></span>         </div>
        </div>
    </div>
    
<!--
<select name="interior">
                    <option value="Outdoor">Outdoor</option>
                    <option value="Ванная">Ванная</option>
                    <option value="Гардеробная">Гардеробная</option>
                    <option value="Гостиная">Гостиная</option>
                    <option value="Детская">Детская</option>
                    <option value="Кабинет">Кабинет</option>
                    <option value="Кухня">Кухня</option>
                    <option value="Прихожая">Прихожая</option>
                    <option value="Спальня">Спальня</option>
                    <option value="Столовая">Столовая</option>
        </select>
-->
    
    <div class="content-body">
        <div id="filter-udnlx" class="filterudnlx container mt-4">
            <form data-sf-form-id="1022" data-is-rtl="0" data-maintain-state="" data-results-url="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/" data-ajax-url="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/?sf_data=all" data-ajax-form-url="http://udnlxdemo.ru/mebelmultimarka_wp/?sfid=1022&amp;sf_action=get_data&amp;sf_data=form" data-display-result-method="custom" data-use-history-api="1" data-template-loaded="0" data-lang-code="ru" data-ajax="1" data-ajax-data-type="html" data-ajax-links-selector=".page" data-ajax-target="#filter-result" data-ajax-pagination-type="normal" data-scroll-to-pos="0" data-init-paged="1" data-auto-update="1" data-auto-count="1" data-auto-count-refresh-mode="1" action="http://udnlxdemo.ru/mebelmultimarka_wp/katalog/" method="post" class="searchandfilter" id="search-filter-form-1022" autocomplete="off" data-instance-count="1"><ul><li class="sf-field-category" data-sf-field-name="_sft_category" data-sf-field-type="category" data-sf-field-input-type="select">        <label>
                <select name="_sft_category[]" class="sf-input-select" title="">
            
                        <option class="sf-level-0 sf-item-0 sf-option-active" selected="selected" data-sf-count="0" data-sf-depth="0" value="">Все рубрики</option>
                        <option class="sf-level-0 sf-item-5" data-sf-count="27" data-sf-depth="0" value="katalog">Каталог&nbsp;&nbsp;(27)</option>
                        <option class="sf-level-1 sf-item-58" data-sf-count="1" data-sf-depth="1" value="dekor">&nbsp;&nbsp;&nbsp;Декор&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-74" data-sf-count="1" data-sf-depth="2" value="zerkalo">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Зеркало&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-1 sf-item-9" data-sf-count="6" data-sf-depth="1" value="kuxni">&nbsp;&nbsp;&nbsp;Кухни&nbsp;&nbsp;(6)</option>
                        <option class="sf-level-2 sf-item-10" data-sf-count="3" data-sf-depth="2" value="bytovaya-texnika">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Бытовая техника&nbsp;&nbsp;(3)</option>
                        <option class="sf-level-1 sf-item-11" data-sf-count="16" data-sf-depth="1" value="mebel">&nbsp;&nbsp;&nbsp;Мебель&nbsp;&nbsp;(16)</option>
                        <option class="sf-level-2 sf-item-37" data-sf-count="3" data-sf-depth="2" value="banketki-i-pufy">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Банкетки и пуфы&nbsp;&nbsp;(3)</option>
                        <option class="sf-level-2 sf-item-38" data-sf-count="1" data-sf-depth="2" value="bary">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Бары&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-39" data-sf-count="1" data-sf-depth="2" value="biblioteka">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Библиотека&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-40" data-sf-count="1" data-sf-depth="2" value="bufet">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Буфет&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-41" data-sf-count="1" data-sf-depth="2" value="veshalki">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Вешалки&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-43" data-sf-count="1" data-sf-depth="2" value="garderobnaya">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Гардеробная&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-42" data-sf-count="1" data-sf-depth="2" value="detskaya">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Детская&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-61" data-sf-count="1" data-sf-depth="2" value="divan-raskladnoj">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Диван раскладной&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-22" data-sf-count="2" data-sf-depth="2" value="divany">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Диваны&nbsp;&nbsp;(2)</option>
                        <option class="sf-level-2 sf-item-87" data-sf-count="1" data-sf-depth="2" value="kaminy">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Камины&nbsp;&nbsp;(1)</option>
                        <option class="sf-level-2 sf-item-88" data-sf-count="2" data-sf-depth="2" value="komody">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Комоды&nbsp;&nbsp;(2)</option>
                        <option class="sf-level-2 sf-item-94" data-sf-count="1" data-sf-depth="2" value="krovat">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Кровать&nbsp;&nbsp;(1)</option>
                    </select>
        </label>        </li><li class="sf-field-post-meta-producer" data-sf-field-name="_sfm_producer" data-sf-field-type="post_meta" data-sf-field-input-type="select" data-sf-meta-type="choice"><h4>Производитель</h4>      <label>
                <select name="_sfm_producer[]" class="sf-input-select" title="">
            
                        <option class="sf-level-0 sf-item-0 sf-option-active" selected="selected" data-sf-depth="0" value="">--</option>
                        <option class="sf-level-0 " data-sf-count="2" data-sf-depth="0" value="440">Cesar</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="442">Minotti</option>
                        <option class="sf-level-0 " data-sf-count="2" data-sf-depth="0" value="444">Livingdivani</option>
                        <option class="sf-level-0 " data-sf-count="3" data-sf-depth="0" value="446">Gaggenau</option>
                        <option class="sf-level-0 " data-sf-count="2" data-sf-depth="0" value="448">Porada</option>
                        <option class="sf-level-0 " data-sf-count="2" data-sf-depth="0" value="450">Poliform</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="452">Selva</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="454">Fiam</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="456">Tumidei</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="458">Olivieri</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="803">Punt</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="829">Milanobedding</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="847">Flou</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="862">Antonio Lupi</option>
                    </select>
        </label>        </li><li class="sf-field-post-meta-type" data-sf-field-name="_sfm_type" data-sf-field-type="post_meta" data-sf-field-input-type="select" data-sf-meta-type="choice"><h4>Тип</h4>        <label>
                <select name="_sfm_type[]" class="sf-input-select" title="">
            
                        <option class="sf-level-0 sf-item-0 sf-option-active" selected="selected" data-sf-depth="0" value="">--</option>
                        <option class="sf-level-0 " data-sf-count="17" data-sf-depth="0" value="Аксессуары">Аксессуары</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="Диван раскладной">Диван раскладной</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="Зеркало">Зеркало</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="Камин">Камин</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="Комод">Комод</option>
                        <option class="sf-level-0 " data-sf-count="1" data-sf-depth="0" value="Кровать">Кровать</option>
                    </select>
        </label>        </li><li class="sf-field-post-meta-interior" data-sf-field-name="_sfm_interior" data-sf-field-type="post_meta" data-sf-field-input-type="select" data-sf-meta-type="choice"><h4>Интерьер</h4>       <label>
                <select name="_sfm_interior[]" class="sf-input-select" title="">

Мне нужно что бы при url "каталога" select с name="_sft_category[]" выбрал option c value="katalog", при url "кухни" select с name="_sft_category[]" выбрал option c value="kuxni" и т.д.

Итак, выборки select при определенном url я добился с помощью подсказки Stepan Kasyanenko и такого кода:

window.onload = function (){
if (location.href == "http://udnlxdemo.ru/mebelmultimarka_wp/katalog/")
   {
     document.querySelector('select[name="_sft_category[]"]').selectedIndex = 1;
   }
if (location.href == "http://udnlxdemo.ru/mebelmultimarka_wp/katalog/kuxni/")
   {
     document.querySelector('select[name="_sft_category[]"]').selectedIndex = 4;
   }
}

Теперь появился вопрос, как заставить отработать клик по этой опции, что бы сработали фильтры на этой странице без перезагрузки? Вставка такого кода как document.getElementById('search-filter-form-1022').submit(); зацикливает выполнение и страница постоянно обновляется....


Ответы (0 шт):