The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Get value of checked box

Labels

This Discussion is public

Notifications

I thought this would be easy, but I can't find the exact method to retrieve the value of a checked box.

I tried input[name='item_meta[74][]']:checked.val

I'm just trying to retrieve the value of each checked item, pre-pend that value with some text and seperate each value with a comma (or just append a comma to all items.) I haven't created the loop yet, but here is the core of my code:

jQuery(document).ready(function($)
{
$('input[name="item_meta[74][]"]').change(function()
{
var propTypes = "";
var checkboxes = document.getElementsByName('item_meta[74][]');
for (var n = checkboxes.length, i = 0; i < n; i--)
{
propTypes = '&idx-q-PropertyTypes%3C0%3E='concat(input[name='item_meta[74][]']:checked.val);

}
$("#field_qc4u2").val(propTypes);
$("#field_qc4u2").change();
});
});

 

Are all of the checked boxes within the same group or are you using individual checkboxes?

If you are using individual checkboxes, you just need its value:

$("#field_224zki-0:checked"). val()

If you are using groups, you have to loop through the group:

var values = new Array();
$.each($("#field_224zki-0']:checked"), function() {
values.push($(this).val());
});

Thank you, I could not find that simple instruction anywhere!

Discussion closed.