Input box in the card below accepts value in percentage. Hence, I have got a placeholder in the input box that says Percentage (%).
I want to suffix value with a % symbol when I start entering input.
- Initially, it should be "Percentage (%)". Check #3 "AU Small Finance Bank"
- If the non-zero input value is provided then it should be "{{value}}%". Check #1 "ABB India Ltd"
- If the input value is not provided or if it is 0 then make it back to "Percentage (%)". I want #2 "ACC Ltd" to show "Percentage (%)", because it was touched but no value was provided.
Link to codepen https://codepen.io/agrawalo/pen/NWKaWMm
<input placeholder="Percentage (%)" id="input_{{stock.code}}" class="stock"/>
JS code:
$('.stock').on('focus click', function() {
$(this)[0].setSelectionRange(0, 0);
$(this).val('%');
})