0
I made a progress bar with bootstrap. Then each time something is filled in the table a certain percentage more is inserted in the bar. The data that is entered into the table comes from an API, so it does this automatically. I did it as follows:
function Progresso(){
var progressTest = document.querySelector('.info-nome');
var teste = progressTest.textContent || progressTest.innerText;
var cont = teste.length;
if (cont > 0) {
var Porc = document.getElementById('progresso_Id').style.width = "5%";
}
}
If the class that comes from the api that contains the name is filled in, that is, it is more than 0, it will insert 5% in the progress bar. But unfortunately it doesn’t work as I want it to. Another example of the rest of my code:
function Prog() {
var progressTest = document.querySelector('.info-cpf');
var teste = progressTest.textContent || progressTest.innerText;
var cont = teste.length;
if (cont > 0) {
var Porc = document.getElementById('progresso_Id').style.width = "10%";
}
}
That is, it is not adding +5%, but 10%, so if the name is not inserted and Cpf yes, it already goes to 10%
How do I insert +5% and no longer change the width of the progress bar? The progress bar is by bootstrap
<div class="container conteudo">
<div class="row nospace">
<div class="progress">
<div class="progress-bar progress-bar-danger active progress-bar-striped progresso" id="progresso_Id" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width:0%">
<span class="sr-only">0%</span>
</div>
</div>
</div>
</div>
And you can do this in pure javascript? If possible, I would also like to know how put to show how much percent already has in the bar for the user to see
API:
var endereco = `http://api`;
$.ajax({
url: endereco,
crossDomain: true,
complete: function(res){
var meuJSON = JSON.parse(res.responseText);
var a = [meuJSON];
a.forEach(function(element) {
console.log(element);
for (var i = 0; i < 1; i++) {
element[i]
var adiciona = element;
AdicionaNome(adiciona[1]);
AdicionaCPF(adiciona[1]);
AdicionaProduto(adiciona[1]);
AdicionaCidade(adiciona[1]);
AdicionaCodigoProduto(adiciona[1]);
AdicionaCodigoCliente(adiciona[1]);
AdicionaStatus(adiciona[1]);
AdicionaEntPrevista(adiciona[1]);
AdicionaEntregaProgramada(adiciona[1]);
The variable
teste.length
returns the values from 0-100? You can create a variable to store the value and then add up to 5 + 5.– Valdeir Psr
test.length returns the amount of characters you have in the given class
– Maria
@maria puts the html inputs
– Julio Henrique
@Juliohenrique Has no html input
– Maria
The API data you mentioned comes in the form of JSON or itself API render HTML? I couldn’t understand
– Matheus Cuba
@Matheuscuba I format it in JSON, then create a td by js to insert them. I will put in the question the way q mexo in the API
– Maria