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

Introduction:

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.
<form>
    <input type="text" name="searchArticle" id="clearTxt" />                                           
    <input type="button" value="Search" id="button" />
</form>
  • 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

0 comments:

Post a Comment

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 .

 
Top