Having a weird issue with jQuery/JavaScript. I’m using this code:
var minimumPercent = $('.donationTextBox').val();
$('.donationTextBox').change(function() {
var donationAmount = parseFloat($('.donationTextBox').val());
donationAmount = donationAmount.toFixed(2);
if(donationAmount < minimumPercent || donationAmount == "NaN") {
$('.donationTextBox').val(minimumPercent);
}
else {
$('.donationTextBox').val(donationAmount);
}
});
This code I’ve written changes the value of an input box (text) so the value entered by the user is in money format (EG: 96.49) and also checks to make sure it isn’t lower than the amount in minimumPercent. If it is, then it’ll change the value to minimumPercent.
The problem I’m having is, say if minimumPercent holds 2.50 and the user inputs 100.00, for some strange reason it assumes that 100.00 is lower than 2.50. Although, 200.00 works fine.
Any ideas? Thanks for the help!
Try ParseFloat when you set minimumPercent.
I think the is engine is comparing a string to a float, thus converting your float back to a string and when you do that 100.00 < 2.50 = true do to the left to right alphabetical comparison.
Mike