How can make a program so as to get Search Results in another Window

I am udemy learner of javascript and In one the recent classes I learnt how to format url string the using javacscript.

Now I want to make a program in which user enters the string (say - harry potter) in form text input field and then on clicking button it redirects to second page and display that string search in BING search engine.

I tried to write some code but I failed. Can anybody help me ??

Following are the files I made

pastebin.com/syCzrqEe pastebin.com/AgvCgCif

1 answer

  • answered 2018-02-13 03:13 ezakto

    <form>
    <input type="text" id="myinput">
    <input type="submit">
    </form>
    
    <script>
      document.forms[0].onsubmit = function() {
        var query = document.getElementById('myinput').value;
        window.open('http://www.bing.com/search?q=' + encodeURIComponent(query));
        return false;
      }
    </script>