Fetch checkbox value (from within multifield) | Community
Skip to main content
New Participant
April 19, 2021
Solved

Fetch checkbox value (from within multifield)

  • April 19, 2021
  • 1 reply
  • 1050 views

I need to fetch value of a checkbox which is present in multifield. There is another checkbox and both the checkboxes are having same granite:class. So I am unable to use granite:class to fetch the value of the checkbox. What else ways are possible to fetch the value of the first checkbox?

Cant use this: let ctaDropdown = $(this).find(".cq-dialog-checkbox-showhide")[0].selectedItem.value;

since my other checkbox is also having same class (cq-dialog-checkbox-showhide)

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Asutosh_Jena_

Hi @shaheena_sheikh 

 

You can read the first checkbox value by using the below line of code:

 

var checkValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
alert(checkValue);

 

Complete logic will be like this:

(function ($, document, ns) {
$(document).on("dialog-ready", function () {
$(".coral3-Multifield-item").each(function (index) {
var firstCheckValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
console.log(firstCheckValue);
})
});
})(Granite.$, document, Granite.author);

Hope this helps!

Thanks 

1 reply

Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
April 19, 2021

Hi @shaheena_sheikh 

 

You can read the first checkbox value by using the below line of code:

 

var checkValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
alert(checkValue);

 

Complete logic will be like this:

(function ($, document, ns) {
$(document).on("dialog-ready", function () {
$(".coral3-Multifield-item").each(function (index) {
var firstCheckValue = $(this).find(".cq-dialog-checkbox-showhide").eq(0).find(".coral3-Checkbox-input").is(":checked")
console.log(firstCheckValue);
})
});
})(Granite.$, document, Granite.author);

Hope this helps!

Thanks 

New Participant
April 19, 2021
what is eq(0)?