I don’t know if this option is for you, but there are two forms of "bar" you can do this. using value increments and showing a percentage in the bar. In the example below it determines 60% of 100
Using the tag progress
the bar shows the evolution of a value, it needs a known total value and vc can go making increments. https://www.w3schools.com/tags/tag_progress.asp
<progress value="60" max="100"></progress>
The other option is the tag meter
it determines a percentage of a total. It is not a progress bar, it just shows a value X between a crease given, it is often used to show when space is occupied on a disk for example. https://www.w3schools.com/tags/tag_meter.asp
<meter value="2" min="0" max="10">3 out of 10</meter><br>
Option with Javascript
This script only allows you to type in the input numbers from 0 to 100, note that there are not 100 characters, but numbers up to 100. And after input has a span with %. Sometimes it can serve you.
function limite(e) {
try {
var element = e.target
} catch (er) {};
try {
var element = event.srcElement
} catch (er) {};
try {
var ev = e.which
} catch (er) {};
try {
var ev = event.keyCode
} catch (er) {};
if ((ev != 0) && (ev != 8) && (ev != 13))
if (!RegExp(/[0-9]/gi).test(String.fromCharCode(ev))) return false;
if (element.value + String.fromCharCode(ev) > 100) return false;
}
window.onload = function () {
document.getElementById('texto').onkeypress = limite
}
input {
font-size: 24px;
width: 3ch; /* largura do campo */
padding-right: 0.25em;
padding-left: 0.25em;
margin-right: 0.5rem;
text-align: right; /* alinha texto a direita */
}
<input type="text" id="texto" maxlength="3" /><span>%</span>
Michel, what kind of mask would that be? Separate the numbers by decimal places? As the maximum percentage is 100%, as it would be to limit the entered value (by what I read in the comments of the posted answers)?
– Sam
Oops. Each employee has a commission to be received calculating the percentage of their commission on the value of the service provided. Example in practice: The employee provided the "X" service that costs R $ 50,00 and has a percentage of 20,48% on each service. With this I will have how to calculate how much he should receive "commission". It is precisely this percentage field that I want to use... if the administrator type 2048, the field becomes 20.48. The same thing I will apply in the monetary field, but without the need to limit it to 100. I will comment in the @Leandro reply what I have achieved so far
– Michel
You can use an attribute
oninput="código aqui"
in the field to make the mask using a JS code where havecódigo aqui
.– Sam
It would look something like this: https://jsfiddle.net/4Ldomnr2/
– Sam
@dvd, that would be exactly what it would be. According to responses and tests done with the primeNg component I think I will have to use the mask via JS itself. That’s a very good example of you. You would only have to adjust to when you choose the value via the component of the number (arrows) the value is in the field because it is cleaning or when you type a value and use the arrows to increment/decrement it puts 100%... but it is in this line same.
– Michel
Check now: https://jsfiddle.net/4Ldomnr2/2/
– Sam
That’s it!! Thank you very much @dvd! I will understand what you did to have a notion... I was researching and I found some angular masks (ng2-currency-Mask and ng2-money-Mask) that I think can also use.
– Michel
In this one I left commented in function form for better visualization: https://jsfiddle.net/4Ldomnr2/4/
– Sam
@dvd, if possible put your comment as the topic response so I can put as accepted the problem. Thanks again!
– Michel