Question: When I'm copy/paste this code, trying use in another place of same Html file both javascript code stops working? Why?
**How I call js code to another form in my code below??**

```html
 <form name="randform">
    <input class="reload-but" type="button" value="↻ " onClick="randomString();">&nbsp;
        <div class="unnec">              
    <input class="random-but" type="button" name="randomfield" value="">
    </form>

    <script language="javascript" type="text/javascript">
    function randomString() {
     var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
     var string_length = 8;
     var randomstring = '';
     for (var i=0; i<string_length; i++) {
      var rnum = Math.floor(Math.random() * chars.length);
      randomstring += chars.substring(rnum,rnum+1);
     }
     document.randform.randomfield.value = randomstring;
    }
    </script>
                        </div> 
```

Answer: 
The reason that it does not work when you put this code in multiple places in the same HTML file is because when you have one form with name `randform`, it returns that form. But since you have multiple form with the same name `randform`. The `document.randform` now returns an array of form.

---

This is quick fix (might not be the recommended way).

```html
...
<input
  class="reload-but"
  type="button"
  value="↻ "
  onClick="randomString(this);"
>
...

```

```
function randomString(input) {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum,rnum+1);
    }

    // no longer rely on the form name.
    input.parentElement.randomfield.value = randomstring;
}

```
I'm having no problems with this. Remove the div closing that is unnecessary in this context and separate your html and javascript as this is generally good practice

```js
function randomString() {
  var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
  var string_length = 8;
  var randomstring = '';
  for (var i = 0; i < string_length; i++) {
    var rnum = Math.floor(Math.random() * chars.length);
    randomstring += chars.substring(rnum, rnum + 1);
  }
  document.randform.randomfield.value = randomstring;
}
```

```html
<form name="randform">
  <input class="reload-but" type="button" value="↻ " onClick="randomString()">&nbsp;
  <div class="unnec">
    <input class="random-but" type="button" name="randomfield" value="">
</form>
```