The following code works only if I don't first type in the textarea box. If i type in it, clicking on the div does nothing. Is there any way to fix this in javascript or whatever? Any help is appreciated.
<textarea id = "textarea">change this</textarea>
<div onclick = "change()">click here<div>
<script>
function change()
{
document.getElementById( 'textarea' ).innerHTML = 'new text';
}
</script>
here is the jsfiddle /
The following code works only if I don't first type in the textarea box. If i type in it, clicking on the div does nothing. Is there any way to fix this in javascript or whatever? Any help is appreciated.
<textarea id = "textarea">change this</textarea>
<div onclick = "change()">click here<div>
<script>
function change()
{
document.getElementById( 'textarea' ).innerHTML = 'new text';
}
</script>
here is the jsfiddle http://jsfiddle/69n24agz/
Share Improve this question asked Dec 28, 2014 at 6:44 user4330208user43302081 Answer
Reset to default 6Change innerHTML to value,
<textarea id = "textarea">change this</textarea>
<div onclick = "change()">click here<div>
<script>
function change()
{
document.getElementById( 'textarea' ).value = 'new text';
}
</script>
a textarea has a value that can be altered, the innerHTML here just sets the initial value.