Answer the question
In order to leave comments, you need to log in
What's wrong with the filter?
Good evening, help me solve the riddle, I broke my whole brain. I want to transfer the filter from a checkbox to a select. When you press the select button, the filter url becomes incorrect...
There is a filter in the form of a checkbox
{* Фильтр по свойствам *}
{if $features}
{foreach $features as $key=>$f}
{* Название свойства *}
<div class="h5 bg-info p-x-1 p-y-05" data-feature="{$f->id}">{$f->name}</div>
<div class="m-b-2 p-x-05">
{* Сброс всех свойств *}
<div style="width: 45%; float: left;">
<label class="c-input c-checkbox">
<input onchange="window.location.href='{furl params=[$f->url=>null, page=>null]}'" type="checkbox"{if !$smarty.get.$key} checked{/if}/>
<span class="c-indicator"></span>
<span data-language="{$translate_id['features_all']}">{$lang->features_all}</span>
</label>
</div>
{* Значения свойств *}
{foreach $f->options as $o}
<div style="width: 45%; float: left;">
<label class="c-input c-checkbox">
<input onchange="window.location.href='{furl params=[$f->url=>$o->translit, page=>null]}'" type="checkbox"{if $smarty.get.{[email protected]} && in_array($o->translit,$smarty.get.{[email protected]})} checked{/if}/>
<span class="c-indicator"></span>
{$o->value|escape}
</label>
</div>
{/foreach}
</div>
{/foreach}
{/if}
{if $features}
<form method=get enctype="multipart/form-data">
<table id="features">
{foreach $features as $key=>$f}
<tr>
<td class="feature_name">
{$f->name}:
</td>
<td>
<select class="c-input feature_values" size="1" data-feature="{$f->id}" name="{$f->id}">
<option value="">Выбрать</option>
{foreach $f->options as $o}
<option value="{$o->translit}" {if $fil[$f->id] == $o->translit}selected{/if}>{$o->value}</option>
{/foreach}
</select>
</td>
</tr>
{/foreach}
</table>
<input type="submit" value="Показать">
</form>
{/if}
Answer the question
In order to leave comments, you need to log in
The checkboxes use a forced change of window.location.href to onchange - this causes the page to be reloaded with the new parameters. Building a classic form and sending parameters by name attributes does not even smell. (Probably because of the "numeric" names of the get parameters).
a) In select, you need to analyze in the same way on the onchange event which option was selected and construct a url using the same method to reload the page with new parameters, substituting a new url in window.location.href.
b) Another option. Change the "Show" button type to button and add an onclick handler that will still generate a link for window.location.href instead of submitting the form in the classic way.
PS: Honestly, I've never seen get parameters have a purely numeric name, except for those cases where the # anchor is used.
I think this is bad naming practice. I would use at least one character in front of the name, for example,
?p1=1&p256=23
Comment on who is in the subject of such subtleties.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question