HubDB queryparam from user input

Is it possible, and if so how, to use the selected option from a dropdown list as a queryParam of another query

<select id="chooseOffice">
 <option value="all">All</option>
 {% set offices = hubdb_table_rows(XXXX) %}
 {% for row in offices %}
 <option value="{{ row.name }}">{{ row.name }}</option> 
 {% endfor %}
</select>

/* Here i want the selected option from 'offices' above to be 'queryParam' of the list below. 

{% set queryParam = ???? %}

*/

<div class="employee-list"> 
 {% set employees = hubdb_table_rows(YYYY, queryParam) %} 
 {% for row in employees %} 
 <div class="single-employee-wrapper"></div>
 {% endfor %}
</div>
	​

I’d use the select to set a query string on the url. Then call the param in your hubDB query

request.query_dict.YOUR_PARAM

Oh, you’ll probably also need a version of your HubDB call without the parameter for when there’s no string query.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact

Thanks for the reply. Would this solution need a page refresh in order to work, or can it be solved without a page refresh? The latter would be prefrerred.

Yes it would require a page refresh. You can’t feed live data into a hubl function like that.

To do that you’d need to use the API.

A possible work around if you’re set on not having a page refresh and can’t go the API route would be to display all as default. Then hide the non-selected items when the drop-down is set. Use JavaScript to set a hide class on non-selected ones or something like that.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact