How do I make a textbox value get updated each 1 sec (for example)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I make a textbox value get updated each 1 sec (for example)?

In web script

22nd Oct 2016, 10:09 AM
Jac1nto
Jac1nto - avatar
2 Answers
+ 1
Hi! You can use the setInterval method. Here is an example: <html> <body> <form> <input type="text" id="counter" size="20"> </form> <script> var count = 0; var timerID = setInterval(function(){ updateText(); }, 1000); function updateText() { textField=document.getElementById('counter'); textField.value = 'Counter: ' + ++count; if (count==10) { clearInterval(timerID); } } </script> </body> </html>
23rd Oct 2016, 6:35 PM
yugor
0
Thank you very much
23rd Oct 2016, 7:26 PM
Jac1nto
Jac1nto - avatar