pretty simple issue here, this was working before but not anymore.
heres my code:
$('.filter-price').submit(function(e) {
var alert_message = '';
var price_from = $('.filter-price #price_from').val();
var price_to = $('.filter-price #price_to').val();
if (isNaN(price_from) || isNaN(price_to))
{
if (isNaN(price_from))
{
alert_message += "Price from must be a number, i.e. 500\n";
$('.filter-price #price_from').val('From');
}
if (isNaN(price_to))
{
alert_message += "Price to must be a number, i.e. 500\n";
$('.filter-price #price_to').val('To');
}
}
else
{
price_from = price_from.toFixed();
price_to = price_to.toFixed();
if (price_from >= price_to)
{
alert_message += "Price from must be less than price to\n";
$('.filter-price #price_from').val('From');
$('.filter-price #price_to').val('To');
}
}
if (alert_message != '')
{
e.preventDefault();
alert(alert_message);
}
});
now web developer is giving me the error “price_from.toFixed is not a function” and my javascript is not working.
First of all ‘isNaN’ function does not REALLY check whether string represents number. For example isNaN(‘456a’) returns true, but ‘456a’ is not number at all. For this purpose you need other method of checking. I would suggest to use regular expressions.
Then you need to parse string for compareing numbers ( i.e. price_from < price_to ).
Here is the modificated code you may assume: