Skip to content
Advertisement

How to add variable inside google URL in Javascript? I have tried but in Google it shows up meaning of “Undefined”

When I run it shows me the meaning of “Undefined” in Google.

When I run it, it performs a Google search for the word “Undefined”.

JavaScript

Advertisement

Answer

If the #search field cannot be found document.getElementById() returns undefined, which is used as part of the search query.

You can write a function like this, which will allow you to pass in a value to be searched.

JavaScript

Or stick with your code but set a default value in the event that the selector does not return a match

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement