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>
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>

<textarea  class="copyFrom"  rows="4" cols="20">TextArea1 </textarea>
<textarea class="copyFrom" rows="4" cols="20"  >TextArea2 </textarea>
<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>
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 );
function myFunction() {
  document.getElementById("field2").value = document.getElementById("field1").value;



Typos. Remember, JS is case sensitive

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

should be

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

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


1 Like

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