jonmrich jonmrich - 8 months ago 62
jQuery Question

Get value from radios as boolean instead of string

I have a function like below to get the values of a series of radio that can either be True or False.

universalDetails = ['thing1', 'thing2', 'thing3'];
$.each(universalDetails, function(idx, name) {
universalDetails[idx] = {
name: name,
value: $('input[name=' + name + ']:checked', '#universalAttributes').val()

However, when I run this, the
comes back as a string ("True" or "False") versus a boolean. How can I adjust this to ensure I return a boolen and push into

Answer Source

You can use .is() to check the current element

value: $('input[name=' + name + ']', '#universalAttributes').is(':checked')

OR Use the length property

value: $('input[name=' + name + ']:checked', '#universalAttributes').length > 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download