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.

closed as off-topic by fuxia Nov 28 '15 at 1:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

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

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. – daniyalahmad Nov 18 '15 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. – Mateusz Marchel Nov 18 '15 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 – Mateusz Marchel Nov 18 '15 at 13:04

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