How to create a blinking effect using Javascript

Hi all,

Some time when you use Ajax to do an action you want to give the user an


indication that the action took place and everything went well. For example you have a text field that onchange action calls for a Javascript function that takes the value, sends it to PHP file, the PHP file gets the value and update the db and sends back to the Javascript function ‘Save’ message.

Now you want to display this message, but you also want that it will blink and disappear lets say after 3 seconds. Easy. All you have to do is from the Javascript function that gets the PHP value call to blinky function

<script type="text/javascript">
function blinky(it) {
  obj = document.getElementById(it);
  if (obj.style.visibility == "visible")
    {obj.style.visibility = "hidden";}
  else
    {obj.style.visibility = "visible";}
}

blink = setInterval("blinky's1')", 250);
</script>
<span id="s1">Save...</span>

and don’t forget to pass the div id as well…

Hope it helps!

Leave a Reply