How to Preselect a Top Level Category - Homepage Search Box

Link: https://support.brilliantdirectories.com/support/solutions/articles/12000089580-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


  1. Copy and paste that code into the Footer JavaScript Input field of the Homepage:



  2.  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:



  3.  Save the change:


Now the homepage automatically preselects the category with the ID specified within the code: