Is countdown on the PLACEHOLDER possible?

Asked

Viewed 43 times

2

I would like to know first if it is possible this, and also disable the input where the placeholder is until the count is finished and when the count is finished enable again? any draft? jquery and the most suitable?

1 answer

0

With jQuery it gets very easy, look here an example below:

$("#btnClick").click(function(){
  var cont = 10;
  var interval = setInterval(function(){
    cont--;
    $("#myInput").attr("disabled", true );
    $("#myInput").attr("placeholder", cont );
    if(cont == 0){
      $("#myInput").attr("disabled", false );
      clearInterval(interval);
    }
  },1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<input type="text" id="myInput" placeholder="10" />
<button id="btnClick">Go Contagem!</button>

  • That’s right, but there in case the boot giving Ubmit to the function, will not give conflict when I add to send information? Another thing when you type something and click on the countdown, jquery does not count again.

  • The principle is this one I showed you, then you use it for your need, I put the button to make it easy to see when you start the count.. When you type something you have to delete the text at the click of the button because placeholder only appears when the input is really empty

Browser other questions tagged

You are not signed in. Login or sign up in order to post.