The problem is that when I type in a number such as 18.0 my code gets to 18, where I want my user to freely type in 18.06. But my code doesnt let the user go above 18.0.
My Fiddle
https://jsfiddle.net/dev2804/cf8vwrbj/1/
function Process() {
var AUS = 1; //CURENY RATE CAN BE CHAGNED BUT THE COUNTRIES IT SELF WON'T, ITS NOT A PART OF THE ASSIGNMENT.
var YEN = 82;
var YAUN = 5;
var RUPIAH = 10000;
var val = event.target.value;
var country = {
"Australia": AUS,
"JapaneseYen": YEN,
"ChineseYuan": YAUN,
"IndonesianRupiah": RUPIAH
};
var countRate;
if (event.target.id == 'countryAustralia') {
countRate = AUS;
} else if (event.target.id == 'countryJapaneseYen') {
countRate = YEN;
} else if (event.target.id == 'countryChineseYuan') {
countRate = YAUN;
} else if (event.target.id == 'countryIndonesianRupiah') {
countRate = RUPIAH;
}
var text = "";
var i;
var rateMp = (val / countRate);
if (val > 0.01 || val < 0) {
for (var i in country) {
var currency = (rateMp * country[i]);
var input = document.querySelector('#country' + i); // select the input by it's ID, I used the country object to build the selector
input.value = currency; // assign the calculated value to the input
}
} else if (val == "") {
for (var i in country) {
var currency = "";
var input = document.querySelector('#country' + i);
input.value = currency;
}
} else if (val.toString() == "0") {
for (var i in country) {
var currency = 0.00;
var input = document.querySelector('#country' + i);
input.value = currency;
}
}
}
<Section class="container">
<Table>
<tr class="RowDesign">
<td class="CountryName">
<div class="CountryText">Australia</div>
</td><br>
<td>
<INPUT placeholder="AUD" type="number" Class="Country" ID="countryAustralia" list="CommonVal" oninput="Process();" onClick="Remove();" />
</td>
</tr>
<tr class="RowDesign">
<td class="CountryName">
<div class="CountryText">Japan</div>
</td><br>
<td>
<INPUT type="number" placeholder="JPY" Class="Country" ID="countryJapaneseYen" list="CommonVal" oninput="Process();" onClick="Remove();" />
</td>
</tr>
<tr class="RowDesign">
<td class="CountryName">
<div class="CountryText">China</div>
</td><br>
<td>
<INPUT type="number" placeholder="CNY" Class="Country" ID="countryChineseYuan" list="CommonVal" onInput="Process();" onClick="Remove();" />
</td>
</tr>
<tr class="RowDesign">
<td class="CountryName">
<div class="CountryText">Indonesia</div>
</td><br>
<td>
<INPUT type="number" placeholder="IDR" Class="Country" ID="countryIndonesianRupiah" list="CommonVal" oninput="Process();" onClick="Remove();" />
</td>
</tr>
<Datalist ID="CommonVal">
<option value=1>1</option>
<option value=10>10</option>
<option value=100>100</option>
<option value=500>500</option>
</Datalist>
</Table>
</Section>
I tried couple of if statements but didn't work. So now I have no idea on how to fix this bug.