Hi. Instead of one “Add Listing” button for all categories, I need a separate page for each category. I tried to implement this with the following js code:
document.addEventListener('DOMContentLoaded', function() {
var params = new URLSearchParams(window.location.search);
var categoryId = params.get('category');
if (categoryId) {
var selectElement = document.querySelector('select[name="categories"]');
if (selectElement) {
selectElement.value = categoryId;
if ($(selectElement).data('select2')) {
$(selectElement).trigger('change');
}
}
}
});
But it doesn’t work exactly as needed. When navigating to the link website.com/submit-listing/details/?category=20
, ?category=26
, or ?category=28
, the value of the Category field changes correctly. However, the corresponding fields and checkboxes that are supposed to appear based on the selected category do not show up. Ideally, when a specific category is selected via the URL, all related fields and options for that category should be automatically displayed on the form.
Can you tell me how to solve the problem?
Thanks.