'I'm trying to capture some text contents from a HTML file, and populate it to another HTML file using Javascript, but why my codes don't work?

I have two HTML files, and I want to change the content of one HTML file by the content of another one. Here are the code segments:

original.html:

<p id="old_1">this is old data</p>

new.html:

<textarea id="new_1" rows="8" cols="80"  style="width:100% !important;"></textarea>
<input type="button" onclick="popData()" id="button_1" value="Send" style="width:100% !important;"/>

I also have a separate js file with function:

function popData()
{
var newContent=document.getElementById("new_1").value;
document.getElementById("old_1").innerHTML=newContent;
}

When I write some thing in the text area, and click the button, the function popData() is called, but when I come back to the original.html, nothing has been changed. Do I need to use PHP? Is it possible to implement it with Javascript and HTML only? And no Iframe.



Solution 1:[1]

As these are two separate html files, there is no means of data flow between them.

document.getElementById("new_1").value should work fine if both textarea and <p> tag is on a single html file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Satya S