First, the href
in your links should just be set to the URL where you want to navigate to. Using javascript:...
inline with your HTML is a 25+ year old technique that isn't used in modern coding.
Your event handlers should be set up in JavaScript, not inline with your HTML and while I'll show you how to accomplish the main effect with JQuery, this is hardly a reason to use JQuery, as this is a quite trivial thing to do without it.
// Set up an event listener on the document (or any ancestor
// of the individual items that might trigger the event)
document.addEventListener("click", setText);
// All event handlers are automatically passed
// a reference to the event they are handling
function setText(event) {
// Check to see if the event was triggered by one of the links
if(event.target.classList.contains("link")){
// Set the value of the input to the text of the element that was clicked
$("#searchBox").val($(event.target).text()); // JQuery
//document.getElementById("searchBox").value = event.target.textContent; // Vanilla JavaScript
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="searchBox">
<a class="link" href="#">Example 1</a>
<a class="link" href="#">Example 2</a>
<a class="link" href="#">Example 3</a>
<a class="link" href="#">Example 4</a>
And, if you are not actually navigating anywhere when the links are clicked, then you shouldn't be using hyperlinks in the first place - they are only for navigation and if you don't use them for that, it can cause accessibility problems. If this is the case, just replace them with an inline element like span
(the rest of the code will still work as it is).