How to Preselect a Top Level Category - Homepage Search Box
When using one of the homepage search modules that allows the user to select a Top Level category, the field to select the category is blank and has placeholder text "Select an option".
This instructs the user to use the dropdown in order to make their selection:
However, depending on the site, preselecting the most popular category can be very useful.
Achieving this requires the use of the code outlined below:
<script> $(document).ready(function(){ select2OnFormClick(); setTimeout(function () { var setId = 2; $("#sid").val(setId); $("#sid").trigger('change'); }, 1000); }); </script>
Implementing the Code
- Copy and paste that code into the Footer JavaScript Input field of the Homepage:
- Replace the 2 with the ID of the Top Level Category that the dropdown will preselect:
The category ID can be obtained within the Member Categories page: - Save the change:
Now the homepage automatically preselects the category with the ID specified within the code: