is it possible to somehow affect the hash of the URL from the `<input>` tag?

I need to initiate a search without a page refresh, but also want to change the URL hash, for example: `search.html#query=hello%20world`, when I have typed `hello world` in particular `<input>` and hit Enter (or submit).

UPD: I have an AJAX search, but I want to keep the history back and forward buttons working. 

So, each time the user searches something, I want him to stay at the same page, load search results via AJAX and change the page's URL hash to enable the history buttons.