i have a form,if user keyin number, the output will be in decimal (this work). and what i want is, if user didn't key in the value in field A, and go to field B by using Tab button, the field A still in blank instead of NAN. or if user keyin in field A/B then delete it, the value in that field will be blank instead return 0/NAN. please help me
$('.Currency').keyup(function(){
// value is either the inputed numbers or 0 if none
let val = parseFloat($(this).val());
if (isNaN(val)) {
$(this).val('');
}
});
$('input.Currency').on('blur', function() {
const value = this.value.replace(/,/g, '');
this.value = parseFloat(value).toLocaleString('en-US', {
style: 'decimal',
maximumFractionDigits: 2,
minimumFractionDigits: 2
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
field A
<input class="numeric Currency" type="text" />
field B
<input class="numeric Currency" type="text" />
i try this, but it still give me a NaN
if (isNaN(val)) {
$(this).val('');
}