javascript - Launch a google search using an input box -
the problem have is: have inputbox , submit button launch google search query.
there 2 ways want search query launched: 1. pressing submit button 2. pressing enter in inputbox
now can in form, thing can't use form because screws webpage in internet explorer.
so far i've managed 1. (pressing submit button) work. can't figure out 2. (pressing enter) work. need google search open in new window.
<input id="textbox" type="text" placeholder="search on google..."> <a id="googlelink" href="notrequired" onclick="this.href='http://www.google.com/search?q=' + encodeuricomponent(document.getelementbyid('textbox').value);"> <span>search</span> </a>
thanks in advance!
the following should work,
add keypress handler on input , check event 13 (enter), , write re-direction logic in there.
<input id="textbox" type="text" placeholder="search on google..." onkeydown="if (event.keycode == 13 || event.which == 13) { location='http://www.google.com/search?q=' + encodeuricomponent(document.getelementbyid('textbox').value);}" />
Comments
Post a Comment