How to create a simple Clear value box with JAVASCRIPT and HTML blogger coding tips script JS Tutorials
In this post, we learn how to create an HTML, javascript script with a clear button with an input value field textarea box When the input field gets clicked, replace its current value with an empty string
:
HTML;
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /></head><body><textarea id="message" name="message" rows="5" cols="33"></textarea><button id="btn">Clear value</button><script src="index.js"></script></body></html>
JAVASCRIPT
<script>const textarea = document.getElementById('message');// Clear textarea valuetextarea.value = '';// Clear textarea value on clickconst btn = document.getElementById('btn');btn.addEventListener('click', function handleClick() {// log value before clearing itconsole.log(textarea.value);// clear textarea valuetextarea.value = '';});</script>
Try to insert any text or script inside the box to implement clear button order in below
Output:
Comments :
Post a Comment