How to append the string to textarea using javascript -
i want append given string textarea have, want append text in way should typing on texture,because have voice playing in background 6 seconds which says same thing written.
<textarea id='typeable' style='font-size:18px;background:#f8e71c'></textarea> <script> function addtext(event) { document.getelementbyid("typeable").value += "hello welcome new world of javascript" } </script>
how can
count number of characters in sentence, , calculate time each char dividing total time no. of characters , call time interval , run until characters printed.
still can decide time taken print each character , modify per need. please note time taken in milliseconds.
var chars = "hello welcome new world of javascript".split(""); var textarea = document.queryselector('textarea'); var total_time=6000; var index = 0; var time_per_char = total_time/chars.length; var t = setinterval(function(){ textarea.value += chars[index]; index++; if (index === chars.length){ clearinterval(t); } },time_per_char);
<textarea style="width:100%;background:#e1ecf4"> </textarea>
Comments
Post a Comment