0

I am trying to make some sort of search engine, I have the input set up, but I need to load the searched tearm into my results page, I am using javascript for this, 1 page for input, one file to store the data, and 1 file to output the data.

INPUT:

var inputBox = document.getElementById("input-box");
var searchButton = document.getElementById("search-button");
var input = "";

searchButton.onclick = function() {
    input = inputBox.value;
    input = input.toLowerCase();
    console.log("Input: " + input);
    getData(input);
}

DATASTORE:

var storeSearchedTearm = "";

getData = function(whatToStore) {
    console.log("Database collection: " + whatToStore);
    storeSearchedTearm = whatToStore;
    console.log("Database added to store: " + storeSearchedTearm);
}

OUTPUT:

console.log("Data: " + storeSearchedTearm);

var searchedTearm = "";

searchedTearm = storeSearchedTearm;

console.log("Output: " + searchedTearm);
j08691
  • 204,283
  • 31
  • 260
  • 272
Callum S
  • 213
  • 2
  • 10
  • 2
    And your question is...? – j08691 Apr 10 '20 at 16:31
  • 1
    Does this answer your question? [Passing Variable through JavaScript from one html page to another page](https://stackoverflow.com/questions/27765666/passing-variable-through-javascript-from-one-html-page-to-another-page) – Omri Attiya Apr 10 '20 at 16:34
  • How are you doing the searching? If it's on the server, you send the search string to it using POST. – Barmar Apr 10 '20 at 16:34

1 Answers1

1

You can store your searched query in Localstorage after pressing Search button in index.html, and get that value in results.html. Try my solution.

Index.html

var inputBox = document.getElementById("input-box");
var searchButton = document.getElementById("search-button");
var input = "";

searchButton.onclick = function() {
    input = inputBox.value;
    input = input.toLowerCase();
    console.log("Input: " + input);
    localStorage.setItem("searchedQuery",input );
    getData(input);
}

Results.HTML or any place you want to see your saved data:

var SearchedQuery = localStorage.getItem("searchedQuery");
Elman Huseynov
  • 1,127
  • 1
  • 8
  • 18