1

I have a page with a form. When an user fills the forms and submits it, it runs a js code. I would like that code to make changes to my other webpage. Specifically to add submitted data to a table that is on the second page. Reading the data is no problem, but is there a way to inject them elsewhere?

Let's say I have code like this:

const val1="val1";
const val2="val2";

And I would like to enter these value to table on another page.

var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = val1;
cell2.innerHTML = val2;

But I do not know how to reference that other webpage.

Also, I am very new to website development. Is there an easier way to store just a little bit of data? I have only a basic hosting, I am not sure if database is part of it.

Jan Horčička
  • 671
  • 1
  • 11
  • 26

2 Answers2

1

HTTP is a 'stateless' protocol. If you want to store data you should consider using Session Cookies or HTML5 LocalStorage.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies

And here is a good briefing on HTML local storage by w3schools https://www.w3schools.com/html/html5_webstorage.asp

DivyaMaheswaran
  • 886
  • 1
  • 12
  • 16
0

Check this example, it might help you: Transfer data from one HTML file to another

Do remember in JavaScript pages cannot share the data with each other without storing. So we must store the data in params, cookies, localStorage, etc to share it.

Karan Dhir
  • 731
  • 1
  • 6
  • 24
  • Thank you, but I need to run the script without interfering with current webpage. In other words, user clicks some button, gets some "Thank you" message and that's it for him. In the meantime, the data is saved to the other webpage, but he does not know about it. Or maybe I am overcomplicating it? Surely there must be some easier way to store simple data from an online formular. – Jan Horčička Aug 16 '17 at 14:24