Search code examples
htmlformssearch

How do I give a input a variable and export it


I am trying to make a search engine.

I was expecting it to redirect me. Heres my code

<!doctype html>
<script>
   function show(){
         s=searchForm.searchField.value;
         window.location.replace("https://www.google.com/search?q="+searchField);
      }
</style>
   <form id="searchForm">
         <input type="search" name="searchField" placeholder="Search QuickSearch">
         <input type="submit" value="Search" onclick="show()">
   </form> 

Solution

  • I think what you are trying to do is something like this:

    JS:

    function show() {
      const s = document.getElementById('inputId').value;
      window.location.replace("https://www.google.com/search?q=" + s);
    }
    

    HTML:

    <form id="searchForm" onsubmit="event.preventDefault()">
            <input type="search" name="searchField" id="inputId" placeholder="Search QuickSearch">
            <input type="submit" value="Search" onclick="show()">
        </form>