Question: Got some js animated dots that work fine as text,

```
var dots = 0;

$(document).ready(function()
{
    setInterval (type, 600);
});

function type()
{
    if(dots < 3)
    {
        $('#dots').append('.');
        dots++;
    }
    else
    {
        $('#dots').html('');
        dots = 0;
    }
}

```

but can not use it in the VALUE attribute of my input button (after "processing").

```
<input type="button" value="Pay" onClick="this.disabled=true; this.value='Processing'">

```

How to insert it in the right way?
<http://jsfiddle.net/te58dadw/2/>

Answer: 
in jQuery use `.attr('value', '.....')` or `.val()`

```js
var dots = 0;

$(document).ready(function() {
  $('#payDots').on('click', function() {
    $(this).attr('disabled', 'disabled');
    setInterval(type, 600);
  })

});

function type() {
  var dot = '.';
  if(dots < 3) {
    $('#payDots').val('processing' + dot.repeat(dots));
    dots++;
  }
  else {
    $('#payDots').val('processing');
    dots = 0;
  }
}
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input id="payDots" type="button" value="Pay">
```
You'd use jQuery's `val()` to set the value, and with a callback it's easy to append to the value.

A small plugin that handles this could be useful, something like

```
$.fn.dots = function(time, dots) {
  return this.each(function(i,el) {
    clearInterval( $(el).data('dots') );

    if ( time !== 0 ) {
      var d = 0;
      $(el).data('dots', setInterval(function() {
        $(el).val(function(_,v) {
          if (d < dots) {
            d++;
            return v + '.';
          } else {
            d = 0;
            return v.substring(0, v.length - dots)
          }
        })
      }, time));
    }
  });
}

```

Which you'd call like

```
$('.elements').dots(600, 3);

```

and can be cancelled by just passing zero

```
$('.elements').dots(0);

```

Here's a demonstration showing how easy it is to use.

```js
$.fn.dots = function(time, dots) {
  return this.each(function(i,el) {
    clearInterval( $(el).data('dots') );

    if ( time !== 0 ) {
      var d = 0;
      $(el).data('dots', setInterval(function() {
        $(el).val(function(_,v) {
          if (d < dots) {
            d++;
            return v + '.';
          } else {
            d = 0;
            return v.substring(0, v.length - dots)
          }
        })
      }, time));
    }
  });
}

$(document).ready(function() {
  $('#dots').on('click', function() {
    $(this).val('Proccessing').prop('disabled',true).dots(600, 3);

    $('#cancel').show();
  });

  $('#cancel').on('click', function() {
    $(this).dots(200, 10);
    $('#dots').dots(0);
    setTimeout(function() {
      $('#dots').prop('disabled', false).val('Pay');
      $('#cancel').hide().dots(0);
    },2000);
  }).hide();
});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="dots" type="button" value="Pay" />
<br /><br />
<input id="cancel" type="button" value="Cancel dots" />
```