I'm new to JS I have input and textarea I want to reset the textarea's value, if input is changed
<!doctype html>
<HTML lang="en">
<HEAD>
<META charset="utf-8">
<META name="viewport" content="width=device-width, initial-scale=1">
<TITLE>Hello, world!</TITLE>
</HEAD>
<BODY>
<INPUT type="text">
<TEXTAREA>AAAA</TEXTAREA>
</BODY>
</HTML>
You can achieve this real quick with Jquery as follows:
$('input').change(function() {
$('textarea').val('');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<input type="text">
<br/><br/>
<textarea>AAA</textarea>
You can replace .change with .keyup if you want the textarea value to reset immediately input is typed on.
input event triggers:
.change: Fires the moment the value of input is changed or clicked out of.
.keyup: Fires when a key is released on input.
.keydown: Fires when a key is pressed down on input.
Modify your HTML code as follows:
<!doctype html>
<HTML lang="en">
<HEAD>
<META charset="utf-8">
<META name="viewport" content="width=device-width, initial-scale=1">
<TITLE>Hello, world!</TITLE>
</HEAD>
<BODY>
<INPUT type="text" id="inputField1" onInput="document.getElementById('textarea1').innerHTML = '';">
<TEXTAREA id="textarea1" >aaa</TEXTAREA>
</BODY>
</HTML>