I am trying to create a simple alphabetizer using HTML's textarea and JavaScript. The user enters their words in the input textarea and when a button is pressed, the alphabetized list will show up on the output textarea. I can't seem figure out how to make it work. Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset = "utf-8" />
<title>Alphabetizier</title>
</head>
<body>
<h1>Meico's Alphabetizer</h1>
<button onclick="alphabetize()">Alphabetize!</button>
<textarea input="inputText" rows=5 cols=80 wrap=on></textarea>
<textarea output="outputText" rows=5 cols=80 wrap=on readonly></textarea>
<script>
var textarea = document.getElementById("input");
function alphabetize() {
textarea.value = textarea.value.split(" ").sort().join(" ")
}
</script>
</body>
</html>
Whenever I click on the alphabetize button, I get the message "TypeError: textarea is null". There is no output on where the output textarea.