I've created a simple calculator that subtracts 20% off any number which is entered into the input field.
I'm trying to display commas and decimal places on the entered number and the returned number.
Here is a link to my fiddle.
https://jsfiddle.net/s0nta9we/1/
<div class="salary-container">
<h3 class="u-h4 u-margin-none">I want to see the breakdown for a salary of</h3>
<span class="salary-input"><span class="salary-pound">£</span> <input type="number" min="17500" class="quantity input-text" name="quantity"></span>
<button id="SubmitBtn" class="button submitbtn" value="Submit">Calculate</button>
</div>
<div class="valueDisplayed">
<div class="valueDisplayed__item new-salary-container"">
<span class="result yearly font-bold"></span>
</div>
$(document).on('click', '.submitbtn', function (e) {
e.preventDefault();
var inputtedSalary = $(".quantity").val(),
num = parseFloat(inputtedSalary),
val = num - (num * .20),
yearValue = $(".yearly");
if (inputtedSalary === '') {
yearValue.text('please enter a value');
}
if (inputtedSalary <= 17499) {
yearValue.text('');
} else if (inputtedSalary >= 17500) {
yearValue.text(val);
}
});
I'm new to JS so not really sure how to tackle this.
Any suggestions or advice would be great.
Thanks