How to get text of chosen checkbox

If there a way to get the text of a chosen checkbox item?

The Checkbox works a lot like the Radiobutton:

$("#Checkbox1_" + Checkbox1.value).val()

You have to allow for multiple checkboxes being checked - see the Checkbox docs for that.

I knew it would be close to the radiobutton solution for this - thanks!

Cindy

How does one get the text of the chosen checkboxes? I tried this - did not work. It had the user pick as many as needed from the checkbox, then click a button.

btnProcessChoices.onclick=function(){

     for (i = 0; i < chxTVShows.length; i++) {
            console.log(`The chxTVShows.getValue(i) for i = ${i} is ${chxTVShows.getValue(i)}`)
            console.log("*******************")
            if (chxTVShows.getValue(i)) {
               //choice[i] = i;
               console.log(`${$("#chxTVShows_" + chxTVShows.value).val()}`)
            }
     }
}

The output is fine except it outputs the text ‘Resident Alien’ for each choice instead of the text by the checkbox:

Seems the code $("#chxTVShows_" + chxTVShows.value).val()} doesn’t change.

DemoFeb21.appstudio.zip (17.2 KB)

The getValue and setValue on CheckBox BS4 control has the value of true or false (checked or unchecked). If you want the contents of the “label” of selected items, you’ll need to access the CheckBox_contents div and iterate the text from each form-check-label label token.

Since I set the checkbox contents from an array using setValue, I don’t examine the divs, or I would post some code.

I don’t know how to do this…

Cindy

Cindy, took me a while to get some time between my wife’s radiation treatments. Here’s some code that worked in chrome console against one of my bs4 checkbox controls

abc = CheckBox.getElementsByClassName('form-check-label')
for (xi = 0; xi < abc.length,xi++) {
console.log(abc[xi].innerHTML);
};

@cindycc - you were close. Try this:

btnProcessChoices.onclick=function(){

     for (i = 0; i < chxTVShows.length; i++) {
            console.log(`The chxTVShows.getValue(i) for i = ${i} is ${chxTVShows.getValue(i)}`)
            console.log("*******************")
            if (chxTVShows.getValue(i)) {
               //choice[i] = i;
               console.log(`${$("#chxTVShows_" + i).val()}`)
            }
     }
}

Excellent thanks!