Hello here I'm trying to Output my function on two separate divs in my project but if I simply output the same I'd it cancels the whole code and nulls the output here is the code.
<script>
function randomString() {
//initialize a variable having alpha-numeric characters
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
//specify the length for the new string to be generated
var string_length = 10;
var randomstring = '';
//put a loop to select a character randomly in each iteration
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
//display the generated string
document.getElementById("randomfield").innerHTML = randomstring;
}
</script>
Then on the body I use
<body onload="randomString();">
<div>
<p id="randomfield"></p>
</div>
</body>
The thing is I want to Output the same string on the page but on a different div maybe at the footer but if I proceed to add
<body onload="randomString();">
<div>
<p id="randomfield"></p>
</div>
<hr>
<footer>
<p id="randomfield"></p>
</footer>
</body>
On the same page it cancels the whole code and nullifies the output. How do I fix this i barely have knowledge of Js
sandr:D