I
I
Ilya Filonov2020-05-14 10:46:56
JavaScript
Ilya Filonov, 2020-05-14 10:46:56

Select tag states?

Good afternoon.

In the standard Opencart code, the filter is triggered by pressing the "Search" button. Here is her code:

$('.filter-item').on('click', function() {
  filter = [];
  $('input[name^=\'filter\']:checked').each(function(element) {
    filter.push(this.value);
  });
  location = '{{ action }}&filter=' + filter.join(',');
});

The thing is that the standard filter is implemented through input:checkbox. In my template, the filter is made through select.
How can I change this line so that the filter works as soon as the user selects one of the tags inside ? After all, it does not have a checked state, like a checkbox ('input[name^=\'filter\']:checked')optionselect

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Polos, 2020-05-14
@dimovich85

Yes, but there are selectedIndex and selectedOption properties.
There is also an event for all form elements: 'change', fired when there was interaction with the input field, focus was lost and data changed - you can subscribe to it and read the properties of e.target.selectedOption, e.target.selectedIndex...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question