SubSea SubSea - 3 months ago 6x
HTML Question

Passing javascript variable from one html page to another page

Hello All i started working on html recently,but iam struck in this situation where i want to send a value from one html page to the next html page just like,how websites shows our name after sign up success.Here i have written two html pages with,


<!DOCTYPE html>
<meta charset="UTF-8">
color: lightgreen;}
<p id="p1" class="myP" onclick="myFun()">DataSend</p>
function myFun(){
document.getElementById("p1").style.color = "blue";
var textprevi=document.getElementById("p1").innerHTML;
localStorage.setItem("message", textprevi);"pageTwo.html","_self");

and my second


<!DOCTYPE html>
<body onload="fun">
<input type="text" id="tBox">
function fun()
document.getElementById("tBox").innerHTML = localStorage.getItem("message");


But when i tried the above solution,the element with id = "tBox" was empty but i wanted it to be filled with value = "DataSend" which is from pageOne.html.
Please help me with the promblem.
Thanks in advance.


The problem is with this line

document.getElementById("tBox").innerHTML = localStorage.getItem("message");

Here tBox is a an input element. So you have to use value instead of innerHTML

document.getElementById("tBox").value= localStorage.getItem("message");