so on my website im using google custom search engine, when i search example 'youtub' not 'youtube'it shows as a suggestion (Showing results for youtube - Search instead for youtub) or (Did you mean: youtube)
so when i click on text youtube, I want to add it on my searchbox, how i can do it? this is my code
searchbox .html
<form action="" method="GET" id="searchform">
<input required="" type="search" name="q" id="searchbox" placeholder="Search..." title="Search..." enableAutoComplete="true" autofocus/>
<button><div class="Search-Button"><img src="MYIMGHERE" class="search-png"/></div></button>
</form>
.js
<script type="text/javascript">
(function() {
var cx = '007072537540236505002:fsvzbpwgtgc';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
var urlParams = new URLSearchParams(window.location.search);
document.getElementById('searchbox').value = urlParams.get('q');
</script>
<gcse:searchresults-only linktarget="_self"></gcse:searchresults-only>
my question is not very clear because I don't find the right words! im so sorry for that.
The solution!
$(document).on('click', '.gs-spelling', function(e) {
window.location.search = 'q=' + ($(this).find('i').text());
document.getElementById('searchbox').value = ($(this).find('i').text());
});