I have two HTML files index.html and display.html with their respective JS files index.js and display.js. I export an object person and updated the object property person.marks upon click event within index.js . I realize that display.js will import the original value of person.marks and the property is updated at a later time on clicking. However, is it possible to access the updated values and display them on the new HTML page through display.js . Do I need to use Promises or other concepts of javascript?
Within index.html
<body>
<p id="here">Click Here</p>
<script type="module" src="index.js"></script>
</body>
Within index.js
export let person = { name:"Ranger" , marks: 23};
var s = document.getElementById("here");
if(s){
s.addEventListener('click',update);
}
function update(){
person.marks = person.marks + 10;
console.log('Updated value in original file ' , person.marks);
}
Within display.html
<body>
<p>The updated value is: </p>
<p id="updatedVal"></p>
<script type="module" src="display.js"></script>
</body>
Within display.js
import { person } from './index.js';
document.getElementById("updatedVal").innerHTML = person.marks; //But this gives the original value