I have a result coming from PHP side and json_encode send all the values as string (not as it's original type). The string coming at quote_tax is a 1|0 and of course this is true|false for example:
{
"country_id": "3",
"country_name": "Italy",
"contract_tax": "1",
"quote_tax": "0",
"contract_inflation": "0",
"quote_inflation": "0"
}
When I want to perform some operation based on such values and because they are coming as string I need to do something like this:
data.quote_tax == '1'
? $('#contract_tax').val(1).attr('checked', 'checked')
: $('#contract_tax').val(0).removeAttr('checked');
I did know about .parseInt() to convert them into a integer but I believe then I would need to have the same comparison but this case comparing with INT:
data.quote_tax == 1
? $('#contract_tax').val(1).attr('checked', 'checked')
: $('#contract_tax').val(0).removeAttr('checked');
I have tried this way:
Boolean(data.quote_tax) == true
? $('#contract_tax').val(1).attr('checked', 'checked')
: $('#contract_tax').val(0).removeAttr('checked');
And it doesn't work since Boolean(data.quote_tax) always evaluate as true even if data.quote_tax = '0'.
I have check this posts already but I couldn't found a proper solution:
Any ideas what's wrong here or how to do this?