Click here to Skip to main content
15,878,809 members
Articles / Web Development / HTML
Tip/Trick

Blinking Text in TextBox using Javascript

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
24 Nov 2011CPOL 27K   3   1
Blinking Text in TextBox using Javascript

Description


After seeing this question[^] in Q/A section, I just created this thing in Javascript & now posting here.

Code


XML
<html>
<head>
<title>Blinking Text in TextBox using Javascript</title>
<script language="javascript" type="text/javascript">
var timer;
function BlinkingText()
{
 if(document.getElementById("txtName").value == "")
 {
   document.getElementById("txtName").value = "Enter your name..";
 }
 else
 {
   document.getElementById("txtName").value = "";
 }
 timer = setTimeout("BlinkingText()", 500);
}

function StopBlinking()
{
  clearTimeout(timer);
}

function ContinueBlinking()
{
  if(document.getElementById("txtName").value == "Enter your name.." || document.getElementById("txtName").value == "")
  {
    BlinkingText();
  }
}

function DoFocus()
{
  if(document.getElementById("txtName").value == "Enter your name.." || document.getElementById("txtName").value == "")
  {
    document.getElementById("txtName").value = "";
    StopBlinking();
  }
}
</script>
</head>

<body onload="BlinkingText()">
Name : <input type="text" id="txtName" value="Enter your name.." onfocus="DoFocus();" onblur="ContinueBlinking();" />
</body>
</html>

Browser Compatibility


I have tested this script in the following Web browsers:

  • Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Safari
  • Opera

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMy 5 Pin
King Fisher1-Apr-15 8:01
professionalKing Fisher1-Apr-15 8:01 
Good to see if you provide any demo or screenshots.
நெஞ்சு பொறுக்கு திலையே-இந்த
நிலைகெட்ட மனிதரை நினைந்துவிட்டால்

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.