I am beginner web developer I have problem with checking numbers in JS.
My code:
function checkValidateForm() {
let errorWidth = false;
let errorHeight = false;
let errorDepth = false;
if (parseFloat(cupboardMinWidth) <= parseFloat($('.product-size').val()) && parseFloat(cupboardMaxWidth) >= parseFloat($('.product-size').val())) {
errorWidth = false;
} else {
errorWidth = true;
}
if (parseFloat(cupboardMinHeight) <= parseFloat($('.product-height').val()) && parseFloat(cupboardMaxHeight) >= parseFloat($('.product-height').val())) {
errorHeight = false;
} else {
errorHeight = true;
}
if (parseFloat(cupboardMinDepth) <= parseFloat($('.product-depth').val()) && parseFloat(cupboardMaxDepth) >= parseFloat($('.product-depth').val())) {
errorDepth = false;
} else {
errorDepth = true;
}
if ($('.product-size').val() == "" || $('.product-height').val() == "" || $('.product-depth').val() == "" || errorWidth === true || errorHeight === true || errorDepth === true) {
$('.product-add-to-basket').attr("disabled", true);
if (errorWidth === true) {
$('.product-info-box1').html('Wymagana szerokość to: <b>' + cupboardMinWidth + 'cm -' + cupboardMaxWidth + 'cm </b><br/>');
$('.product-info-box1').fadeIn("slow");
} else {
$('.product-info-box1').fadeOut("slow");
}
if (errorHeight === true) {
$('.product-info-box2').html('Wymagana wysokość to: <b>' + cupboardMinHeight + 'cm -' + cupboardMaxHeight + 'cm </b><br/>');
$('.product-info-box2').fadeIn("slow");
} else {
$('.product-info-box2').fadeOut("slow");
}
if (errorDepth === true) {
$('.product-info-box3').html('Wymagana głębokość to: <b>' + cupboardMinDepth + 'cm -' + cupboardMaxDepth + 'cm </b><br/>');
$('.product-info-box3').fadeIn("slow");
} else {
$('.product-info-box3').fadeOut("slow");
}
$('.product-info-error-msg').fadeIn("slow");
} else {
$('.product-info-error-msg').fadeOut("slow");
$('.product-info-box1').hide;
$('.product-info-box2').hide;
$('.product-info-box3').hide;
$('.product-add-to-basket').attr("disabled", false);
}
}
let productId = 1;
let cupboardMinWidth = '100.00';
let cupboardMaxWidth = '250.00';
let cupboardMinHeight = '100.00';
let cupboardMaxHeight = '190.00';
let cupboardMinDepth = '140.00';
let cupboardMaxDepth = '190.00';
My preview: http://serwer1356363.home.pl/_nauka/
Wymagana szerokość to: 100.00cm -250.00cm - max width
Wymagana wysokość to: 100.00cm -190.00cm -max height
Wymagana głębokość to: 140.00cm -190.00cm - max depth
When I add values to my inputs, e.g. 100.5, 120.5 etc. - the dimensions messages are not always hidden.
Why?
When my dimensions meet the ranges - the message should hide, and this is not always the case
How can I repair it?
checkValidateFormon every input insertion and on page loadinginputthe mask hasn't "fix" the value so before the number becomes100.5(again, because of the mask code) it is1005.input, use the plugin callbacks e.g.onChange