My HTML:
var searchInput = $("#searchField").val()
$("#searchButton").on("click", function() {
alert(searchInput)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" placeholder="Search.." id="searchField">
<button type="submit" id="searchButton">Submit</button>
With this code, after I click the "Submit" button, I only get an empty alert.