Stack Overflow Asked by mscmdaddcts on December 16, 2021
I’m new to coding and I have to build a mortgage simulator. For that I have a range field where users can choose the number of years which are shown on a first field. And another field where there’s the rates. Is there a way the range control the rates too. I want to suggest the rates for the users this way :
But I also would want them to write their rates, without affecting the number of years. I have come to this so far:
https://jsfiddle.net/f3sy8dh5/
<div class="loans-simulator">
<label for="duration">Loan duration</label>
<input type="range" name="dureeInputName" id="dureeInputId" value="2" min="2" max="30" oninput="dureeOutputId.value = dureeInputId.value" onchange="updateTextInput(this.value);">
<input name="dureeOutputName" id="dureeOutputId" value="0"><br/>
<label for="rates">Rate %</label>
<input id="rates" value="0.0" step=".01" min="0.0">
</div>
If you want to update the rates field on each change of the loan duration field, then here is how to do that
var ratesValue = document.querySelector("#rates");
document.querySelector("#dureeInputId").onchange = function() {
if(this.value >= 2 && this.value <= 9) {
ratesValue.value = 0.75;
}else if(this.value >= 10 && this.value <= 11) {
ratesValue.value = 0.9;
}else if(this.value >= 12 && this.value <= 14) {
ratesValue.value = 1;
}else if(this.value >= 15 && this.value <= 19) {
ratesValue.value = 1.1;
}else if(this.value >= 20 && this.value <= 24) {
ratesValue.value = 1.3;
}else if(this.value >= 25 && this.value <= 29) {
ratesValue.value = 1.65;
}else {
ratesValue.value = 2.18;
}
};
<div class="loans-simulator">
<label for="duration">Loan duration</label>
<input type="range" name="dureeInputName" id="dureeInputId" value="2" min="2" max="30" oninput="dureeOutputId.value = dureeInputId.value" onchange="updateTextInput(this.value);">
<input name="dureeOutputName" id="dureeOutputId" value="2"><br/>
<label for="rates">Rate %</label>
<input id="rates" value="0.75" step=".01" min="0.0">
</div>
Answered by SaymoinSam on December 16, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP