Reputation: 170
I want to be able to write something in a <textarea>
, and then click a button and have the text I wrote in the textarea displayed in another textarea or inside a <div>
.
I'm not sure what code I should try. I'm very new to coding. I tried the following which clearly did not work.
My JS:
<script>
function myFunction(){
var input = document.getElementbyId('input').innerHTML;
document.getElementbyId('output').innerHTML;
}
</script>
My HTML:
<textarea id='input'></textarea>
<textarea id='output'></textarea>
<button onclick= 'myFunction()'>Click</button>
Upvotes: 1
Views: 865
Reputation: 15213
You had an error calling getElementbyId
. And you can use value
to assign a text value. Also, you haven't closed your function.
function myFunction(){
var input = document.getElementById('input');
var output = document.getElementById('output');
output.value = input.value;
}
<textarea id='input'></textarea>
<textarea id='output'></textarea>
<button onclick='myFunction()'>Click</button>
Upvotes: 4