All,
I have the following bit of PHP to check a checkbox:
<input type="checkbox" name="check_out_gear[]" id="'.$resultsetgear['gear_checkout_id'].'" value="'.$resultsetgear['gear_checkout_id'].'" class="gear_checkout_checkbox" checked disabled>
That code works fine and the checkbox is checked and it is disabled. I’m checking to see if it at least one checkbox is checked by using the following jQuery:
var fields = jQuery(".gear_checkout_checkbox").serializeArray();
if (fields.length == 0)
{
jQuery.wl_Alert('Please select a piece of equipment that you\'re checking out!','warning','#no_answers','#workform', {sticky:false});
one_selected = false;
}
When that checkbox is checked and disabled the length is always 0. However as soon as I remove the disabled from the code it has a length of at least 1. Any idea how I can get this code to work with a disabled checkbox?
This is documented behavior for disabled inputs. From the jQuery docs on
.serializeArray():Just check for the length of the checked boxes using the
:checkedselector [jQuery docs], like so: