I can dynamically replace the value of an h1 element with the value of a textarea that is on the same html page. However, once I place several forms on the page, the h1 tag on one form, and place the textarea on another, nothing happens when I try to update the h1 value with the textarea value using ONLY plain Javascript.
I have tried getElementById, getElementByTagName, innerHTML and setAttribute to no avail. Is this impossible or I am missing something? I cannot find a single example on the web that addresses this.
UPDATE:
<form id=form1 action="">
<h1 id="h1tag">I'm H1</h1>
</form>
<form>
<label for='text1'>Change H1:</label>
<input type="textarea" value="" id="text1"/>
<button onclick="newHeading();">newHeading()</button>
</form>
The external javascript:
function newHeading()
{
document.getElementById(h1tag).innerHTML = document.getElementById(text1).value;
}
Use a simple
functionwith the properID‘sThen use it in your
formwith theonsubmit()set toreturn false: