-1

I have an amount field and some JQuery which enables/disables my submit button as shown in my code below, but the issue I have is that if the user enters 00.00 then my button becomes enabled and I don't want it to.

How can i stop it.

JQuery

if ($('#OneOffPayment_Textbox').val() == '' || $('#OneOffPayment_Textbox').val() < '0.01' || $('#OneOffPayment_Textbox').val() == '0.00' && e.options[e.selectedIndex].text == 'BACS')
{
     $('#FeeTotalAmounts').hide();
     $('#OneOffPayment_Submit').attr("disabled", true);
}
else
{
     $('#OneOffPayment_Submit').attr("disabled", false);
}
Seth McClaine
  • 6,298
  • 4
  • 32
  • 53
murday1983
  • 3,124
  • 10
  • 44
  • 85

1 Answers1

1

You are comparing your numbers as strings instead of actual numbers, which means you are basically saying is val before 0.01 in alpha numeric order

you should not be adding quotes around '0.01'

also try casting your vals

if ($('#OneOffPayment_Textbox').val() == '' || 
parseFloat($('#OneOffPayment_Textbox').val()) < 0.01 || 
parseFloat($('#OneOffPayment_Textbox').val()) == 0.00 && 
e.options[e.selectedIndex].text == 'BACS')
Seth McClaine
  • 6,298
  • 4
  • 32
  • 53
  • My disable works fine. The issue is when i add 00.00 instead of 0.00. When the page loads my field displays as 0.00 by default but if i add another '0' (00.00) my button enables – murday1983 Mar 11 '16 at 15:55
  • try casting 00.00 to a double – Seth McClaine Mar 11 '16 at 15:56
  • 1
    Also removed the `parseFloat($('#OneOffPayment_Textbox').val()) == 0.00` as it wasn't needed as i was using `< 0.01` in the condition before it – murday1983 Mar 11 '16 at 16:04