Add '%' and format value in text field

Asked

Viewed 31 times

0

I have a field in shape text:

<input type="text" name="base_calculo" id="base_calculo">

I would like you to add the % symbol at the end of this field and format the field like this: 0.0%

Thank you!

  • You have already tried using the plugin jQuery-Mask-Plugin?

  • I would not like to use a plugin, is this field only... and when filling will see stay 2.5% or if only add the % in the field by jquery, would be good..

  • http://stackoverflow.com/questions/11613642/mask-input-with-percent-sign

1 answer

1

The function does not lock only number in that field

$('#base_calculo').on('blur', function(){
    var valor = $(this).val();
    valor = valor.replace(',','.');

    if(!$.isNumeric(valor)) return;

    valor += '%';

    $(this).val(valor);

});
  • Didn’t work out....

  • It only gives if I click out... I would like when clicking on the field it already added the % and as it fills, put the . certinho

  • 1

    Use the mask money and in the mask I put decimal 1 and have the option there to put a character not remember well

Browser other questions tagged

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