javascript - How to get the value of a html input and preform a google search? - Stack Overflow

I have a form with an input control, and a submit button. I would like the user to be able to enter the

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.

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.

Share Improve this question asked Apr 17, 2011 at 5:26 Carl WeisCarl Weis 7,08215 gold badges65 silver badges86 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Simple html:

<html>
<body>

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

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

</form>

</body>
</html>

Try:

var box=document.getElementById('the_search_box');
window.location='http://www.google./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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745403306a4626200.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信