Short js snippets working with js jquery and bool valuesinput checkboxes

Get value of checkbox (jquery):

$('#myCheckboxInput').attr('checked')

– returns bool true or bool false

Set value of checkbox (jquery):

$('#myCheckboxInput').attr('checked', true)

Second parameter can be true or false.

Convert true or false strings to bool (js):

var myBoolValue = (myString.toLowerCase() === "true");

This is when you know the string will be ‘True’ or ‘FALSE’ for instance. Accepts all case variations of ‘TRUE’ and ‘false’.

Leave a Reply

Your email address will not be published. Required fields are marked *