Coding error? intoCount[0].innerHtml = copyFromVar;

Hello & Thanks:)
copyFromVar = fromCount[0].value ;
is working fine , but
intoCount[0].innerHtml = copyFromVar;
not working .
Pls , what is my coding error ?

<!DOCTYPE html>
<html>
<body>
<h5>Copy-Text-from-textarea-to-div.html</h5>
Field1: <input type="text" id="field1" value="Hello from Field1 !"><br>
Field2: <input type="text" id="field2"><br><br>

<button onclick="myFunction()">Copy text From field1 to field2</button>
<button onclick="saveItAll()">Copy text From textarea to contentEditable-div</button>

<br><br>
<textarea  class="copyFrom"  rows="4" cols="20">TextArea1 </textarea>
<br>
<textarea class="copyFrom" rows="4" cols="20"  >TextArea2 </textarea>
<br>
<div class="pasteInto" contentEditable="false" >pasteInto 1</div>
<div class="pasteInto" contentEditable="true" >pasteInto 2</div>

<p>A function is triggered when the button is clicked. The function copies the text from Field1 into Field2.</p>
<script>
var copyFromVar = ""; 
var fromCount; //  = document.getElementsByClassName("copyFrom");
var intoCount;  //  = document.getElementsByClassName("pasteInto");
function saveItAll() {
  fromCount   = document.getElementsByClassName("copyFrom");
  intoCount    = document.getElementsByClassName("pasteInto");

  copyFromVar = fromCount[0].value ;
  intoCount[0].innerHtml   = copyFromVar;
alert("0 copyFromVar = " + copyFromVar );
  
  copyFromVar = fromCount[1].value ;
  intoCount[1].innerHtml   = copyFromVar;
alert("1 copyFromVar = " + copyFromVar );
  
}
</script>
<script>
function myFunction() {
  document.getElementById("field2").value = document.getElementById("field1").value;
}
</script>

</body>
</html>

Thanks

Typos. Remember, JS is case sensitive

  intoCount[0].innerHtml   = copyFromVar;
  intoCount[1].innerHtml   = copyFromVar;

should be

  intoCount[0].innerHTML   = copyFromVar;
  intoCount[1].innerHTML   = copyFromVar;
3 Likes

Off-topic, IMHO unless you need / want HTML it is better to use

or

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.