javascripthtmlsearchbing

Concatenate search query and preset text to a search


Trying to re-create this search url https://www.bing.com/search?q=site:https://www.imdb.com/title+Hakunamatata

but this code keeps doing the wrong thing. I want to concatenate the URL's. Not start a second query inline

<form method="get" action="http://www.bing.com/search">
    <input type="text" name="q" size="25" maxlength="255" value="Hakunamatata" />
    <input type="hidden" name="q1" value="site:www.imdb.com/title" />
    <input type="submit" value="Bing Search" />
</form>

What I keep getting is URL's with & in them instead of +.
Is there some kind of Javascript or something that can combine the search terms into one search?


Solution

  • You'll need to use JavaScript to prepend 'site:www.imdb.com/title ' to the input's value when the submit event is fired.

    form.addEventListener('submit', function(){
      query.value = 'site:www.imdb.com/title ' + query.value;
    })
    <form method="get" action="http://www.bing.com/search" id="form">
        <input type="text" name="q" size="25" maxlength="255" value="Hakunamatata" id="query"/>
        <input type="submit" value="Bing Search" />
    </form>