Home > other >  Html Search form to submit query to external site, and see the results
Html Search form to submit query to external site, and see the results

Time:06-27

I would like to be able to type a search phrase into an input box, click send, and have a tab open to a new site where the address is something like https://www.w3schools.com/?q=SEARCH_PHRASE. Is there a way to provide this functionality, and show results on the external url. I tried the below code

<form method=get action="https://www.w3schools.com" target="_blank">
<input type=text name=q value="">
<input type=submit value="go">
</form>

and I end up in the index page, not results, any help?

CodePudding user response:

To present a list of search results, code running on the server has to parse the URL and perform the search.

http://www.w3schools.com doesn't pay any attention to the query string. (It has a search form, but it processes it with JS and not with a regular form submission).

https://duckduckgo.com does pay attention to the query string, so

<form method=get action="https://duckduckgo.com/" target="_blank">
  <input type=text name=q value="">
  <input type=submit value="go">
</form>

… would work.

You can't make an arbitrary third-party page pay attention to the query string.

  • Related