Carl Weis
Carl Weis

Reputation: 7072

How to get the value of a html input and preform a google search?

I have a form with an input control, and a submit button. I would like the user to be able to enter their zip code, and then perform a Google search with what they entered into the input field.

I tried searching online, but couldn't find what I was looking for. I already know the query string format for a Google search, just a little rusty on my HTML and JavaScript.

Upvotes: 0

Views: 4082

Answers (3)

Trent Scott
Trent Scott

Reputation: 2028

Checkout the script called LMGTFY (Let Me Google That For You) -- pretty cool implementation.

Upvotes: 0

Khez
Khez

Reputation: 10350

Try:

var box=document.getElementById('the_search_box');
window.location='http://www.google.com/search?q='+escape(box.value);

Here's an example on jsfiddle.

You should consider creating a Google Custom Search though.

Upvotes: 1

magma
magma

Reputation: 8530

Simple html:

<html>
<body>

<form action="http://www.google.com/search" method="get">

<input type="text" name="q">

</form>

</body>
</html>

Upvotes: 5

Related Questions