Clear Textbox or Text-Area After a Specified Time Using Javascript


Today I am going to teach you the way to clear Textbox value after a specified time or seconds. You can use this tutorial in your web application or while you design your website.
  • You have to embed Jquery Java-script Library to make work this tutorial in your web application or program. So don't forget. 

How to Clear Textbox or Text-area After a Specified Time?

It is very easy to clear value from any kind of Text-box or Text-Area value simply by using Java-script. All you want to do, just follow the method that given below. The HTML code that I am using in this tutorial are given below.
    <input type="text" name="searchArticle" id="clearTxt" />                                           
    <input type="button" value="Search" id="button" />
  • On the above HTML code, I used id="clearTxt". By using the ID, Java-script will identify the Text-box and clear the value in it.
  • I also added a id in button as id="button". The function in the Java-script will work only after click the button.
$(function() {
    $("#button").click(function() {
        alert('button clicked'); // this is calling
        setTimeout(function() {
            alert('setTimeout'); // this is not calling
            document.getElementById('clearTxt').value = "";
        }, 5000);
  • The above script will clear Text-box with in 5 seconds after click the submit button. You can change the time  by changing the 5000 to different micro-seconds.
The above real time demo using JSFiddle will help you to test the Java-script. Work with it and copy paste to your web application or website.

 Suggested Article for Developers:

I hope you well enjoyed this article. If you have any doubts or suggestions related to this article. Please let us know by using the comment box given below. Thanks


  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog.
    Really very informative post you shared here. Kindly keep blogging.
    If anyone wants to become a Front end developer learn from Javascript Online Training from India .
    or learn thru JavaScript Online Training from India.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

  2. I love reading the blogs on this platform as they are so easy to understand very informative. Great work!
    seen on screen removal guide


Wapmaster or Webmaster can Comment Us with the following Comment Box . Don't add Links to your site for Spamming our Blog .. Once you add Comment with Link . It will be deleted immediatly by our Admins .