# Need help with a small but faulty script .

**URL:** <https://forum.kirupa.com/t/need-help-with-a-small-but-faulty-script/640415>\
**Category:** Uncategorized\
**Created:** [September 5, 2019, 10:57pm UTC](https://forum.kirupa.com/t/need-help-with-a-small-but-faulty-script/640415 "2019-09-05T22:57:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)\
**Post date:** [September 5, 2019, 10:58pm UTC](https://forum.kirupa.com/t/need-help-with-a-small-but-faulty-script/640415/1 "2019-09-05T22:58:00Z")

</div>

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](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](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:

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

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [September 6, 2019, 12:08am UTC](https://forum.kirupa.com/t/need-help-with-a-small-but-faulty-script/640415/2 "2019-09-06T00:08:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)\
**Post date:** [September 6, 2019, 1:46am UTC](https://forum.kirupa.com/t/need-help-with-a-small-but-faulty-script/640415/3 "2019-09-06T01:46:07Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [September 6, 2019, 4:11am UTC](https://forum.kirupa.com/t/need-help-with-a-small-but-faulty-script/640415/4 "2019-09-06T04:11:10Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/2X/1/15efd60bf1ef477e20af8f7e41c29586d8dc002b.png)

If you fix that, I think you should be all set 🙂

---

<div class="post-metadata">

**Author:** ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)\
**Post date:** [September 6, 2019, 2:56pm UTC](https://forum.kirupa.com/t/need-help-with-a-small-but-faulty-script/640415/5 "2019-09-06T14:56:45Z")

</div>

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 🙂
