Query problems with HTML and Google

Viewed 1029

This is the Link Directly to Google’s “I’m Feeling Lucky” Feature: http://www.google.com/search?q=term&btnI. Where if you change the word ''term'' for any other word, the link works. But the problem comes when I wanna use a html code to make it works by an . What should be the name:"" to make works the link? My code:

<form action="http://www.google.com/search?q=term&btnI">
    <input type="text" placeholder="Search in Google or type a URL" name="q">
    <input type="submit" value="I'm Feeling Lucky">
</form>
2 Answers

You used the parameter 'btnI' in the form action, that doesn't work. Like you added the name parameter name="q" in the 2nd line, similarly you should add a parameter name="btnI" in the 3rd line. This is because, type "submit" is given there, and you should add the parameter ("btnI") to that line where you are submitting the input.

change the 3rd line <input type="submit" name="btnI" value="I'm Feeling Lucky">

When you submit the form, action will take you to the server, which in this case is google website, with the query (input field with name="q") (for example, harvard) equals to what you have typed into the input field and the https address will change to https://google.com/search?q=harvard (altogether with other stuff, but only this one should work). In this way, you requested to the server to give back what you have queried, which is "harvard". And then by add name="btnI", by clicking "I'm feeling lucky", you will be automatically redirected to the website of the first search result.

<form action="https://google.com/search">
    <input type="text" name="q"><br>
    <input type="submit" name="btnG" value="Google Search">
    <input type="submit" name="btnI" value="I’m Feeling Lucky">
</form>

Hope that explains.

Related