Click here to Skip to main content
12,249,279 members (31,546 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

16.9K views
3 bookmarked
Posted

Blinking Text in TextBox using Javascript

, 24 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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

<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)

Share

About the Author

thatraja
Web Developer
India India
Retired from Q/A section & Technical forums since 2014

More coming soon....

You may also be interested in...

Comments and Discussions

 
QuestionMy 5 Pin
King Fisher1-Apr-15 9:01
professionalKing Fisher1-Apr-15 9:01 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 24 Nov 2011
Article Copyright 2011 by thatraja
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid