1
I have an input range that goes from 0 a 400.000
every step of 5.000
and I have a set of plans (50.000, 70.000, 100.000, 120.000, 150.000, 200.000, 220.000, 250.000, 300.000, 350.000, 380.000 e 400.000 )
each plan of this contains different information that will be placed inside a table.
Good need to link the values placed in the user input range to the nearest plan, eg: range value = 20,000 will be linked to the 50,000 plan.
After this process the value will be inserted in (.vcredito values):
makeTable(valores.vcredito, json.planos, document.querySelector('tbody'));
The only values that will work in place of valores.vcredito
are those of the plans, so I need to transform the value of the input range into the value of the nearest plan.
I do not know if it was very clear but something I try to improve the question.
Thank you.
Edited:
I have the following code that assembles a table according to the chosen plan:
const json = {
"planos": [{
"nome": "Imóvel 50",
"credito": "50000",
"100 parcelas": "R$605,00",
"120 parcelas": "R$512,50",
"135 parcelas": "R$462,96",
"150 parcelas": "R$423,33 ",
"180 parcelas": "-"
}, {
"nome": "Imóvel 70",
"credito": "70000",
"100 parcelas": "R$847,00",
"120 parcelas": "R$717,50 ",
"135 parcelas": "R$648,15",
"150 parcelas": "R$592,67",
"180 parcelas": "R$493,89"
}, {
"nome": "Imóvel 100",
"credito": "100000",
"100 parcelas": "R$1.210,00",
"120 parcelas": "R$1.025,00",
"135 parcelas": "R$925,93",
"150 parcelas": "R$846,67",
"180 parcelas": "R$705,56"
}, {
"nome": "Imóvel 120",
"credito": "120000",
"100 parcelas": "R$1.452,00",
"120 parcelas": "R$1.230,00",
"135 parcelas": "R$1.111,11",
"150 parcelas": "R$1.016,00",
"180 parcelas": "R$846,67"
}, {
"nome": "Imóvel 150",
"credito": "150000",
"100 parcelas": "R$1.452,00",
"120 parcelas": "R$1.230,00",
"135 parcelas": "R$1.111,11",
"150 parcelas": "R$1.016,00",
"180 parcelas": "R$846,67"
}, {
"nome": "Imóvel 200",
"credito": "200000",
"100 parcelas": "R$2.420,00 ",
"120 parcelas": "R$2.050,00 ",
"135 parcelas": "R$1.851,85 ",
"150 parcelas": "R$1.693,33",
"180 parcelas": "R$1.411,11 "
}, {
"nome": "Imóvel 220",
"credito": "220000",
"100 parcelas": "R$2.662,00",
"120 parcelas": "R$2.255,00",
"135 parcelas": "R$2.037,04",
"150 parcelas": "R$1.862,67",
"180 parcelas": "R$1.552,22"
}, {
"nome": "Imóvel 250",
"credito": "250000",
"100 parcelas": "R$3.025,00",
"120 parcelas": "R$2.562,50",
"135 parcelas": "R$2.314,81",
"150 parcelas": "R$2.116,67",
"180 parcelas": "R$1.763,89"
}, {
"nome": "Imóvel 300",
"credito": "300000",
"100 parcelas": "R$3.630,00",
"120 parcelas": "R$3.075,00",
"135 parcelas": "R$2.777,78",
"150 parcelas": "R$2.540,00",
"180 parcelas": "R$2.116,67"
}, {
"nome": "Imóvel 350",
"credito": "350000",
"100 parcelas": "R$4.235,00 ",
"120 parcelas": "R$3.587,50",
"135 parcelas": "R$3.240,74",
"150 parcelas": "R$2.963,33",
"180 parcelas": "R$2.469,44"
}, {
"nome": "Imóvel 380",
"credito": "380000",
"100 parcelas": "R$4.598,00",
"120 parcelas": "R$3.895,00",
"135 parcelas": "R$3.518,52",
"150 parcelas": "R$3.217,33",
"180 parcelas": "R$2.681,11"
}, {
"nome": "Imóvel 400",
"credito": "400000",
"100 parcelas": "R$4.840,00",
"120 parcelas": "R$4.100,00",
"135 parcelas": "R$3.703,70",
"150 parcelas": "R$3.386,67",
"180 parcelas": "R$2.822,22"
}]
};
var valorCredito = $('#valores-credito').val();
var valorParcela = $('#valores-parcela').val();
function makeTable(credito, arr, target) {
target.innerHTML = '';
var data = arr.filter(imo => imo.credito == credito)[0];
if (!data) return;
Object.keys(data).filter(k => k.match(/\d+\s\parcelas/)).forEach(k => {
var tr = document.createElement('tr');
[k, '<span aria-hidden="true" class="fa fa-info-circle"></span>Mais informações', data[k]].forEach(content => {
var td = document.createElement('td');
td.innerHTML = content;
tr.appendChild(td);
});
target.appendChild(tr);
});
}
makeTable(valores.vcredito, json.planos, document.querySelector('tbody'));
cool more or less like your same example, I’ll take a look and see how I can adapt to my code, anything notice here, Thank you.
– user27585
I am unable to put in my code, when I give a console.log (sugestao) says that suggest this undefined.
– user27585