Article suggestions
  1. Home
  2. Section: Developer Hub
  3. How to Preselect a Top Level Category - Homepage Search Box

How to Preselect a Top Level Category - Homepage Search Box

How to Preselect a Top Level Category - Homepage Search Box
  • avatar
Written by Chan Nier
Updated on February 19, 2025

 Link: https://support.brilliantdirectories.com/support/solutions/articles/12000089580

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>
JavaScript

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:


Thank you for leaving a rating!
Did you find this article helpful?
0 out of 0 people found this article helpful so far
Can't find what you're looking for? Get in touch
How can we help?
Send your question below and we'll get back to you as soon as possible.
Cancel
translation missing: en.kb.default.contact_form_error
×
Thanks for your message!
Thanks for your message!
×