Skip Navigation

[Resolved] Select a Default Value from a Dropdown Filter and Apply the result to the page

This thread is resolved. Here is a description of the problem and solution.

Problem:
Select a Default Value from a Dropdown Filter and Apply the result to the page

Solution:
if you want to filter the view results as soon as you set the default option for your select dropdown - you need to add JS code to your view's JS box.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/select-a-default-value-from-a-dropdown-filter-and-apply-the-result-to-the-page/#post-1516047

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/views/adding-custom-javascript-views/

This support ticket is created 4 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by brettD-3 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1515815

Tell us what you are trying to do?

Trying to have a results page load a query result and populate the page with a pre-selected value from the options.

Is there any documentation that you are following?
Have followed this documentation https://toolset.com/forums/topic/how-to-prefill-default-value-in-dropdown-box/
and used the JS mentioned in the post.

jQuery(document).ready(function($) {
jQuery("select[name^='wpv-wpcf-city'] option[value='Devonport']").attr("selected","selected");
});

Is there a similar example that we can see?

What is the link to your site? hidden link
This is the page. You will note that we want the "Devonport" option to populate the page when loaded.
This happens after page load. Devonport is selected from the dropdown options but results dont change to filter out any other towns apart from the selected one.

I can go and select another town from the dropdown, the results are filtered. I choose Devonport again and the results are filtered.

Regards
Brett

#1516047

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand, you want to filter the view results as soon as you set the default option for your select dropdown - correct?

If this is correct - can you please try to use the following code:

jQuery(document).ready(function($) {
jQuery("select[name^='wpv-wpcf-city'] option[value='Devonport']").attr("selected","selected").trigger('change');;
});

Does the above code I shared help you to resolve your issue?

#1516085

My issue is resolved now. Thank you!