4

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.

1
  • Is there any way to check it as an actual bool? I'm trying to grab a bool property from my asp.net code-behind and right now I am putting that value into an input field but there's got to be a better way to grab it from JS other than a hidden field? Commented Nov 20, 2009 at 20:32

2 Answers 2

8

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".

Sign up to request clarification or add additional context in comments.

Comments

4

Since the value of the hidden input field is a string, !"False" will be evaluated to false. Note that any string other than a string with the length of 0 is treated as true. So you should rather compare the string value to another string value like "False":

if (itemIsSold == "False") {
    // …
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.