开发者

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.


Simple html:

<html>
<body>

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

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

</form>

</body>
</html>


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜