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);
3
  • 2
    And your question is...? Commented Apr 10, 2020 at 16:31
  • 1
    Does this answer your question? Passing Variable through JavaScript from one html page to another page Commented Apr 10, 2020 at 16:34
  • How are you doing the searching? If it's on the server, you send the search string to it using POST. Commented Apr 10, 2020 at 16:34

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.