I'm creating a lorem ipsum generator and have a lot of fun with it. However, I'm trying to create a button where you can copy the generated text. Where am I going wrong with this?
I have a separate javascript file that generates text successfully into just wondering how exactly to copy it
<body>
<center>
<h1 class="title">Lorem Ipsum Generator</h1>
<p class="description">A Harry Potter lorem ipsum generator.</p>
<form action="/" method="POST">
<input type="number" class="paragraph-number" name="numberOfParagraphs">
<input type="submit" value="Expecto Patronum!" class="generate-button">
<input type="reset" value="clear" class="generate-button">
</form> </center>
<center>
<div class="border"><div id="generated-text">
<div class='placeholder-div'></div>
</div>
</div>
<button onclick="copyPassage()" class="copy-button">Copy text</button>
<script src=/generator.js>
function copyPassage() {
var copyText = document.getElementById("generated-text");
copyText.select();
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}
</script>