I have a website with a 2 html pages. On the landing page, I have bootstraps “cards” which are basically acting like buttons. If you click on one, it’ll link you to the second page.
Here’s one of the clickable “cards”:
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12" id="arrest-data">
<div class="box-part text-center"> <i class="fa-solid fa-3x fa-handcuffs" aria-hidden="true"></i>
<div class="title">
<h3>Data Examples 1</h3>
</div>
<div class="text"> <span>Crime data and other crime statistics</span> </div> <a href="#" class="get-data">GET DATA</a>
</div>
On a separate page, I have a filterable table, with dropdowns to filter different categories:
<div class="container">
<div class="row dropdowns">
<div class="col-4">
<select id="categoryDropdown">
<option value="All">All Topics</option>
<option value="Category: Arrest Data">Arrest Data</option>
<option value="Category: Use of Force">Use of Force</option>
<option value="Category: Human Trafficking">Human Trafficking</option>
<option value="Category: Treatment and Diversion">Treatment and Diversion</option>
<option value="Category: Drug and Overdose Data">Drug and Overdose Data</option>
</select>
</div>
<div class="col-4">
<select id="formatDropdown">
<option value="All">All Formats</option>
<option value="Format: Dashboard">Dashboard</option>
<option value="Format: PDF">PDF</option>
<option value="Format: Data Story">Data Story</option>
<option value="Format: CSV">CSV</option>
</select>
</div>
<div class="col-4">
<select id="associateStatusDropdown">
<option value="All"> All Users </option>
<option value="Yes">Active Users</option>
<option value="No">Inactive Users</option>
</select>
</div>
</div>
<table class="table">
<thead>
<tr>
<th> SL.NO </th>
<th> Data </th>
</tr>
</thead>
<tbody id="download-forms-table-tbody">
<tr>
<td> 1 </td>
<td>
<div class="project-title">
Criminal Arrest Data
</div>
<div class="project-description">
<p>Example Arrest Data blah blah.</p>
</div>
<div class="project-category">
<b>Category</b>: Arrest Data
</div>
<div class="project-format">
<b>Format</b>: Dashboard
</div>
<div class="project-last-update">
<b>Last Updated</b>: 5/16/2022
</div>
<div class="project-associated-data">
<b>Associated Data</b>: 5/16/2022
</div>
</td>
</tr>
<tr>
<td> 2 </td>
<td>
<div class="project-title">
Demographics of Arrest Data
</div>
<div class="project-description">
<p>Example Arrest Data Demographics blah blah.</p>
</div>
<div class="project-category">
<b>Category</b>: Arrest Data
</div>
<div class="project-format">
<b>Format</b>: PDF
</div>
<div class="project-last-update">
<b>Last Updated</b>: 5/16/2022
</div>
<div class="project-associated-data">
<b>Associated Data</b>: 5/16/2022
</div>
</td>
</tr>
<tr>
<td> 3 </td>
<td>
<div class="project-title">
Drug Data
</div>
<div class="project-description">
<p>Example Drug Data blah blah.</p>
</div>
<div class="project-category">
<b>Category</b>: Drug Data
</div>
<div class="project-format">
<b>Format</b>: PDF
</div>
<div class="project-last-update">
<b>Last Updated</b>: 5/16/2022
</div>
<div class="project-associated-data">
<b>Associated Data</b>: 5/16/2022
</div>
</td>
</tr>
</tbody>
</table>
And here’s my javascript for filtering the table using the dropdowns:
$('.container').on("change", 'select', function() {
console.log("changin")
var category = $('#categoryDropdown').val().toLowerCase(),
format = $('#formatDropdown').val().toLowerCase(),
associate = $('#associateStatusDropdown').val().toLowerCase();
var table = $("#download-forms-table-tbody");
var trs = table.find('tr');
trs.hide();
var filtered = trs.filter(function(index, elem) {
var tds_category = $(elem).find('td > div:nth-of-type(3)'); //get the category
var tds_format = $(elem).find('td > div:nth-of-type(4)'); //get the format
var all_tds = $(elem).find('td'); //get all td
//console.log(tds.text())
console.log(tds_format.text())
//console.log(tds.eq(1).innerHTML)
if (category !== "all" && tds_category.text().trim().toLowerCase() !== category) {
return false;
}
if (format !== "all" && tds_format.text().trim().toLowerCase() !== format) {
return false;
}
if (associate !== "all" && all_tds.eq(3).text().trim().toLowerCase() !== associate) {
return false;
}
return true;
})
filtered.show();
if (filtered.length == 0) {
alert("No Records Found!!!");
}
});
When the user clicks on a card on the first HTML page, I want that event to set the dropdown filter to a certain value. In this example, when the user clicks on the card, I want the dropdown to be set to value="Category: Arrest Data".
I’ve tried:
$('#arrest-data').click(function(){
$('#categoryDropdown').val('Category: Arrest Data');
})
But no luck.
Can anyone help me with what is best practice for having an event listener on one HTML page do an action on a different HTML page, like in this scenario?
Thanks!