Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for bool in JavaScript

I've got the following jQuery (I've got it wrapped in the document ready function and all that, so please know I'm just showing you the inside of the function.

..
            var itemIsSold = $("#itemIsSold").val();
            alert(itemIsSold);
            if(!itemIsSold) {
               ...
    }

where itemIsSold is a hidden input field. I get the value False upper case F when it hits the alert but never enters my next if statement. I know this has to be something stupid simple.

like image 273
PositiveGuy Avatar asked Dec 17 '22 04:12

PositiveGuy


1 Answers

If the input's value contains the string "False", that will not translate into a false boolean value. You will need to actually check for itemIsSold == "False".

like image 51
Rudism Avatar answered Dec 19 '22 18:12

Rudism