Need help with a small but faulty script .

Hello & Thanks ;
I am having a problem with a small script called function saveItAll() .
It works fine in this page:
http://vmars.us/ShowMe/Textarea-Save-CopyTo-RestoreFrom-onLoad-Restore-Kirupa.html
But doesn’t work in this page:
http://vmars.us/ShowMe/changeImage-Drag-Create-Restore.html
I have been struggling with this for days now:
Any clues will be greatly appreciated .
Here’s the code:

<script>
var copyFromVar = "one"; 
function saveItAll() {
alert("Hello  from  function saveItAll()");
console.log("Hello  from  function saveItAll()");
var blankVar = "";
var  fromList   = document.getElementsByClassName("copyFrom");
var  intoList    = document.getElementsByClassName("pasteInto");
console.log("fromList.length = " + fromList.length);

  for (var i = 0; i < fromList.length; i++) {
console.log("fromList.length = " + fromList.length);
    copyFromVar = fromList[i].value ;
console.log("copyFromVar = " + copyFromVar);
    intoList[i].innerHTML   = copyFromVar;
console.log("intoList[i].innerHTML = " + intoList[i].innerHTML);
//    fromList[i].innerHTML   = blankVar;
//    fromList[i].value   = blankVar;
  }
}// ========================================
</script> 

Thanks

When I try to save the page in both examples, the HTML file downloads. What should I be seeing? :slight_smile:

OOps;
I was just coming back to clarify
& I noticed you had already answered .
Your quick :slight_smile:
In the 2nd example , the script only executes as far as

var copyFromVar = "one"; 
function saveItAll() {
alert("Hello  from  function saveItAll()");
console.log("Hello  from  function saveItAll()");
var blankVar = "";
var  fromList   = document.getElementsByClassName("copyFrom");
var  intoList    = document.getElementsByClassName("pasteInto");
console.log("fromList.length = " + fromList.length);

and then nothing more . No more console.log()s .
It just stops .
1st example runs fine .
Thanks
The 1st example is a mini-tutorial on how to do some stuff.

That is because your for loop isn’t running. There are no items in you fromList:

If you fix that, I think you should be all set :slight_smile:

1 Like

Ah yes , I see now: I coded:

document.getElementsByClassName(“CopyFrom”);

should be:

document.getElementsByClassName(“copyFrom”);

So

for (var i = 0; i < fromList.length; i++) {

never ran .

Thanks Kirupa :slight_smile:

1 Like