-1

Here is my onblur event with the javascript so far. There are values auto loaded into the box on the page load but if a user deletes the value or enters a value less than zero it should default to 0.00. Right now it is defaulted to NaN.

function checkformat(entry) {    
    test = entry.value;
    if (!isNaN(test)) {
        entry.value=parseFloat(entry.value).toFixed(2);
    }
    else if (isNaN(test) == true) {      
        test.value='0.00';        
    }
    else if (test < 0.00) {
        test.value = '0.00';
    }
    else {
      test.value = '0.00';
    }
    
  }
<input id='Line Item <% line %>' type="text" onkeyup="updateTotal()" placeholder="Amount" name="AmountPaying" class="field m w-input" value="<% r.AmountOwed %>" onblur="checkformat(this)">
epascarello
  • 204,599
  • 20
  • 195
  • 236
jreed21
  • 75
  • 1
  • 7

1 Answers1

0

Use the following funtion for IsNaN control.

function isNumeric(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

New Code

function checkformat(entry) {    
    test = entry.value;
    if (isNumeric(test)) {
        entry.value=parseFloat(test).toFixed(2);
    }
...
selami
  • 2,478
  • 1
  • 21
  • 25