Answer the question
In order to leave comments, you need to log in
How to pass parameters from form to URL?
There is this form:
<form role="form" action="catalog/vse-tovaryi/">
<select name="ms|price">
<option value="">Любая</option>
<option value="500">500 рублей</option>
</select>
<select name="msoption|tags">
<option value="1">Тэг 1</option>
<option value="2">Тэг 2</option>
</select>
<button type="submit">Подобрать</button>
</form>
Answer the question
In order to leave comments, you need to log in
Here's an example dashed off:
HTML:
<form role="form" id="form" action="catalog/vse-tovaryi/" data-def="catalog/vse-tovaryi/">
<select name="ms|price">
<option value="">Любая</option>
<option value="500">500 рублей</option>
</select>
<select name="msoption|tags">
<option value="1">Тэг 1</option>
<option value="2">Тэг 2</option>
</select>
<button type="submit">Подобрать</button>
</form>
window.onload = function () {
var form = $('#form'), def = form.data('def'), data = {}, action;
$(document).on('change', '#form select', function () {
var el = $(this), val = el.val(), name = el.attr('name');
if (val) {
data[name] = val;
} else {
delete data[name];
}
action = def + "?";
for(var i in data) {
action += i + "=" + data[i] + '&';
}
action = action.substr(0, action.length - 1);
form.attr('action', action);
});
};
You can remove this select when clicking on the submit button of the form JS script
Isn't it easier on the handler side to simply ignore the "empty" argument?
I suspect that this has already been done, and your real task is beyond the scope of your question.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question