I have this code:

Search: <input type="text" id="fname" onkeyup="myfunction()">
<a id="sear" href="" target="_blank">Search</a>
function myFunction() {
var  x = document.getElementById("fname").value;
var url = "https://www.google.co.in/search?q=all+"+x+"&biw=1366&bih=643&source=lnms&tbm=isch";

I have implemented this in WordPress and the link is now pointing to the same page rather than opening the google search page.

  • Please add debug information to your question.
    – fuxia
    Nov 18, 2015 at 12:20

2 Answers 2


You have a typo in onkeyup="myfunction()". Your function is named myFunction, not myfunction (function names are case sensitive).

  • But he is looking for to click on submit i believe. Nov 18, 2015 at 12:59
  • 2
    Probably yes, but the question was why the posted code doesn't work, not how to write it better, so i just explained why it doesn't work and what is needed to be done. But you're right, that better option will be just do it once, on click. Nov 18, 2015 at 13:12

There is issue in your JS code and the html that you are not calling your JS function.

Try this code :


Put script in header.php and user HTML in post editor.

PS: Its good practice to enquee the script properly so it goes in footer.

  • There is one problem with your code: window.open(url, '_blank'); will not necessarily open new tab. Look here Nov 18, 2015 at 13:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.