You need to create a filter test for products, there are 3 categories and 3 values, resulting in 27 values ​​depending on the configurations. Each of the values ​​has a separate link, which you get after pressing a button.

как это выглядит

You can change the values ​​in the test in any order and several times and the link from it changes correctly ... hasn’t found anything at all, is not strong in js

  • The answer below helped me to understand how to assign a value, and how to register a link and set each specific value of these categories so that the link is different for each combination? - ev.zdanovich

1 answer 1

It is possible so:

Three hidden fields:

<form method="POST" onsubmit="return false;"> <input type="hidden" value="0" id="category1_value" name="category1_value" /> <input type="hidden" value="0" id="category2_value" name="category2_value" /> <input type="hidden" value="0" id="category3_value" name="category3_value"/> <input type="button" value="Перейти к ссылке" onclick="loadFilterPage()" /> </form> 

Your 9 blocks will have an onclick property:

 <div onclick="document.getElementById('category1_value').value='1'"></div> <div onclick="document.getElementById('category1_value').value='2'"></div> ... <div onclick="document.getElementById('category3_value').value='8'"></div> <div onclick="document.getElementById('category3_value').value='9'"></div> 

And add the script:

 <script> function loadFilterPage(){ // Получаем значения скрытых полей: var cat1value = document.getElementById('category1_value').value; var cat2value = document.getElementById('category2_value').value; var cat3value = document.getElementById('category3_value').value; // Объединяем их в строку: var catsStr = cat1value + "," + cat2value + "," + cat3value; // В зависимости от строки формируем ссылку: var pageHref; switch(catsStr) { case '1,1,1': pageHref = "1.html"; break; case '1,1,2': pageHref = "2.html"; break; case '1,1,3': pageHref = "3.html"; break; ... case '3,3,2': pageHref = "26.html"; break; case '3,3,3': pageHref = "27.html"; break; default: alert('Неверное значение'); break; } // переходим по найденной ссылке: if(pageHref != ''){ setTimeout('location.replace("'+pageHref+'")', 0); } } </script> 

But in general it is strange, in theory there should be one page of the page.php type, it loads by sending the form, there you get the field values ​​in _POST and load the necessary content. But if you need different links - the code above.

  • I see, thanks! And how to prescribe a link and set each specific value of these categories? - ev.zdanovich
  • @ ev.zdanovich Tell me, do you have 27 different pages (of the form /1.html, 2.html and so on) or one page like "1.html", which should be displayed differently depending on the filters? I will supplement the answer then. - Maxim Stepanov
  • These are all different pages (1.html, 2.html and so on) - ev.zdanovich
  • Completed the answer. When you click on a button, the script should follow one of the links. And I changed the old blocks a bit, correct them in your code too. In general, of course, in vain, I wrote all this. Here it is desirable to upload your code, and that does not work. If the answer helped, click "accept" there though =) - Maxim Stepanov
  • one
    hooray! super! I owe you! Thank you very much! You are just a hero! everything works, even better than we wanted - ev.zdanovich