diff --git a/lms/templates/courseware/courses.html b/lms/templates/courseware/courses.html
index 5a9be61bfe1b..da2bcec68179 100644
--- a/lms/templates/courseware/courses.html
+++ b/lms/templates/courseware/courses.html
@@ -93,7 +93,7 @@
- results find for ""
+ find for ""
@@ -327,38 +327,40 @@
% endif
+ document.addEventListener('DOMContentLoaded', function() {
+ var searchForm = document.getElementById('discovery-form');
+ var resultsCountContainer = document.querySelector('.search-results-count');
+ var resultsCount = document.getElementById('results-count');
+ var searchTermDisplay = document.getElementById('search-term');
+ var discoveryMessage = document.getElementById('discovery-message');
+
+ searchForm.addEventListener('submit', function(event) {
+ event.preventDefault(); // Prevents the form from submitting traditionally
+
+ var searchTerm = document.getElementById('discovery-input').value.trim();
+
+ setTimeout(function() {
+ var messageText = discoveryMessage.textContent || '';
+ var numberOfResults;
+ var resultTerm;
+
+ if (messageText.includes("any results")) {
+ numberOfResults = 0;
+ resultTerm = 'results'; // Plural, as "0 results" is the conventional expression
+ } else {
+ numberOfResults = parseInt(messageText.match(/\d+/)[0]) || 0;
+ resultTerm = (numberOfResults === 1) ? 'result' : 'results'; // Singular for 1, plural otherwise
+ }
+
+ // Update the display inside the setTimeout function
+ resultsCountContainer.style.display = 'block';
+ resultsCount.textContent = numberOfResults + ' ' + resultTerm;
+ searchTermDisplay.textContent = searchTerm;
+ }, 500); // Adjust the delay time as needed
+ });
+ });
+
+