0

I am creating a web app where an object property is creating upon clicking a button in the inputs.html page. However, results.html needs access to the created property to prompt the user to save it in firestore.

  • I have already tried importing and exporting the variable but get this error: Uncaught SyntaxError: Unexpected token ).
  • I have tried creating a const variable property in inputs.html that changes using my script but I cannot access it in results.html.
  • I have also screated a script tag in results.html linking to the javascript file where property is created.

Here is inputs.js used to create property and imported in inputs.html.

//create a property and go to results page
document.getElementById("createProperty").addEventListener("click", ()=>{

    property= new Property( document.getElementById("address").value, ..., );

    window.location = "../Frontend/results.html";
});
  }

Here is the code in results.js that calls property and is in the results.html page.

document.getElementById("test").addEventListener("click",(e)=>{

    //example of a possible output
    console.log(property.address); 
});

I would like for the console to log askprice. However, the error received is: Uncaught ReferenceError: property is not defined.

I was wondering what are the methods I could use to access property between these javascrip files.

Migliore
  • 21
  • 1
  • 4

1 Answers1

0

I was wondering what are the methods I could use to access property between these javascrip files.

You can't share any JavaScript state across page loads, that includes variables. The variable property cannot be persisted from one page to the next.

Instead, you need to push your data into some kind of persistent store, like localStorage or sessionStorage, or pass it to the next page via something like the query string, ie results.html?property=askprice.

user229044
  • 232,980
  • 40
  • 330
  • 338