How to make it work?

I made two HTML files and one the first file (sample.html) . I put a text box and a submit button below that.
When I click submit I want it to go the next HTML file (sample2.html). And the text entered in the textbox in sample.html should appear in a

element in sample2.html.
How do I do this??
I tried linking both HTML files to one javascript file but that does not seem to work.

Try this

<form action="sample2.html">
<input type="textarea"/>
    <input type="submit" value="Submit" />

The text entered in the textarea input should be present in sample2.html.
How is that done??

I’m a newbie here. I don’t know much better about using HTML. But I would like to learn. Thanks!

1 Like

You can’t just do this with HTML. You need to save that text somewhere then grab it once the new page opens. You have to at least use JavaScript here. For example you when you click submit, you use JS take the text, append it to the URL of the next page as a query parameter of the next page, and when that page opens, use JS to get the text from the URL and render it to the page. It necessitates using a server whatever you do as well.

Yea, i did all that. I made another JS file and saved the text in localStorage and all that.
But when i clear local storage the text goes. I want the text entered in the textbox of sample.html to be shown in

tag of sample2.html. I used local storage to save the text entered in the textbox but when i clear the local storage it goes away. I tried using variables and all that but not working.
Have any idea how to do this???

Well, yes. You’re deleting the data, I’m not sure what you think will happen there? If you clear the things you need to keep in storage, then they’re gone, you can’t use them.

I know that if i clear local storage the text goes from the local storage in the browser but I dont want it to go away from the HTML tag.

Can you show code you have written for loading text from localStorage to html?

And ofcourse when you clear localStorage the text will go away. HTML will not store any data, so if you remove the source of the storage it will not be visible wherever it is referenced…

The only better way of doing this is by using server side code, or make a single page app using react or plain js.

1 Like