Jquery: Convert string to boolean

hidden-field, jquery

Solution

It depends on the value you're expecting in the hidden field.

I would do something like this:

var hfEntityBool = $(this).find('input[id*="hfEntityBool"]').val() == "true";
if (hfEntityBool) {
    alert(hfEntityBool);
}

Problem

I'm pooling the following values from some hidden fields. ``` var hfEntityBool = $(this).find('input[id*="hfEntityBool"]').val(); if (hfEntityBool) { alert(hfEntityBool); } ``` No matter what the value of the hidden field, the alert still displays. Any reason for that? I've tried to use Boolean(hfEntityBool) method in case the hidden field's still a string, but nothing changed. Thank for helping

Original source