I got a custom search form in my WordPress Blog, i have this search code in my sidebar inside a text widget.
<div class="search-form">
<input type="text" value="" class="input-txt" id="search-txt"/>
<input type="submit" value="Search" class="input-btn" id="idsubmit" onClick="search_redirect()"/>
<script type="text/javascript">
function search_redirect(){
text_val = document.getElementById('search-txt').value;
if(text_val!=''){
url_re = 'http://bizisearch.com/search?page=1&limit=20&engine=spider&type=web&query='+'"'+text_val+'"';
window.location = url_re;
} else {
alert('search input is required');
}
}
window.onload = function(){
document.getElementById('testfield').onkeypress = function(e){
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13'){
search_redirect();
return false;
}
}
}
</script>
</div>
I want the search results to “OPEN IN A NEW TAB” and i can press the “ENTER” key to search….
Is there a tutorial or can you guide me on how to do that???
Thanks
You can’t control how to open in a new tab.
The enter can be accomplished by capturing a click event on your enter key and call your function in that event.
Enter event in JQuery:
Make sure you include JQuery if it is not included:
or follow this guide to include it a better way.
In pure Javascript: (you should give your button an id)