1

I want to blink the placeholder text on focus out .

This is my html code:

<input type="text" id="keyfob" class="customform col-sm-12 text-red" data-required='true' placeholder=" Please click here to Key Fob scanning work">

this is my jquery code:

$('#keyfob').on("focus blur", function(){
    $(this).attr("placeholder") == "" ? $(this).attr("placeholder", "Please click here for Key Fob scanning to work") : $(this).attr("placeholder", "");
});

working js fiddle code

now i want to blink the placeholder text "Please click here to Key Fob scanning work".

So please can anyone help me ???

Bhairav
  • 159
  • 3
  • 17

3 Answers3

0

here's jquery

function blink() {

if ($('input[type=text]').attr('placeholder')) {
 // get the placeholder text
 $('input[type=text]').attr('placeholder', '');
} 
else {
  $('input[type=text]').attr('placeholder', 'Placeholder Text...');
}
setTimeout(blink, 1000);
}

html

<body onload='blink()'>
<input type="text" on-click='blink()' id="keyfob" class="customform col-sm-12 text-red" data-required='true' placeholder=" Please click here to Key Fob scanning work">
Rkn
  • 122
  • 2
  • 11
0

Are you looking something like this:

  <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        var clicked;
        $('#keyfob').focusout(function() {
            var s = $('#keyfob').attr("placeholder");
            clicked=true;
            blinking();    
        });
        $('#keyfob').click(function() {
            clicked=false;
            $('#keyfob').attr("placeholder", '');
        });
        function blinking() {
               if(clicked){
                     $('#keyfob').attr("placeholder", '');
                setTimeout(function() {
                    $('#keyfob').attr("placeholder", 'Please click here to Key Fob scanning work');
                    setTimeout(blinking, 500);
                }, 1000);
            }
        }
      });
   </script>

  </head>

    <body>
         <input type="text" id="keyfob" class="customform col-sm-12 text-red" data-required='true' placeholder="Please click here to Key Fob scanning work">
   </body>
 </html>
Pioter
  • 465
  • 3
  • 8
  • 21
  • thanxs for responding. can u create a jsfiddle for above code,because it is not working for me – Bhairav Feb 12 '15 at 11:13
  • still the cursor and placeholder both are blinking @dileep i dont want blink both of them – Bhairav Feb 12 '15 at 11:16
  • Onfocus the placeholder text should be hide and onfocusout the placeholder text should be seen with the blinking effect. – Bhairav Feb 12 '15 at 11:24
0

See this thread that shows how it can be done with plain CSS only, without any JavaScript / jQuery.

Special credit for @Pinal who helped me to make it work on Firefox.

Community
  • 1
  • 1
Alexander Dayan
  • 2,846
  • 1
  • 17
  • 30