Add '%' and format value in text field

0

I have a field in the format text :

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

I would like you to fill in this field by adding the% symbol at the end of it and typing the field like this: 0.0%

Thank you!

    
asked by anonymous 23.09.2015 / 20:23

1 answer

1

The function does not only block number in this field

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

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

    valor += '%';

    $(this).val(valor);

});
    
23.09.2015 / 20:41