Javascript Checkbox

Just starting to create a javascript function. How do I get the state of a checkbox element in Javascript?

Try to use Toolbox plugin.

Just curious; what are you trying to do?

Want to check the yes/no state in checkbox. Just want to know how to code the line to check the state? I’m currently using Zeroqode’s Javascript plugin. Don’t know if that one or the Toolbox is better for passing individual/list of values back and forth. And if one is easier to work with.

Ok - I switched to using Toolbox. And I tried coding my Action Script to be

setTimeout(function(){bubble_fn_2(document_querySelector(’#PP CanvasToggle Uppercase Letters’);},1000);

But that doesn’t work. Anyone know how to get the value from the checkbox (element name is PP Canvas Toggle Uppercase Letters)?

Hi @s.arndt ,
Refer below forum link,

I assume the checkbox is not a bubble element already?

Nearly there, try either of

document.querySelector('#idOfElement').checked  // returns true if checked
document.querySelector("input[name='nameOfElement']").checked // returns true if checked

You could also setup an event listener, to send the checked value to bubble when it changes.

1 Like

no its bubble element. im just trying to understand how to code the javascript to get its value.

Then either of …
image
image

or using a parameter

image

1 Like

Still not working…Here’s what I’ve tried

var checkedvalue = null;
var cb = document.getElementsByName(ā€˜PP Checkbox Uppercase Letters’).checked;
console.log(cb);
if(cb) {
checkedvalue = cb.value;
}
console.log(checkedvalue);

var aa = document.getElementsByName(ā€œPP Checkbox Uppercase Lettersā€).checked;
console.log(aa);

var cc = document.querySelector(ā€˜PP Checkbox Uppercase Letters:checked’).value;
console.log(cc);

And what I get usually is Undefined or Null - even though the checkbox in Bubble is checked.

image

Please place this text in the element ID attribute like below,
image

I think, you are using the element name instead of element id attribute.

Ok…I set the id attribute as shown below…

And I put change the action item to be:

var cc = document.querySelector(ā€˜#PPCHECKBOXUPPERCASELETTERS’).checked;
console.log(cc);

And I still get an Undefined message in the console when I run the workflow - even thought the checkbox is checked. Not sure what I’m doing wrong.

I can review your code if you drop here a link to your editor.

Run in console mode to see the result being sent as a False value (Null) even though the checkbox is checked.

Your app is private. You need to change in settings to make it visible.

Done…

Hi @s.arndt ,

selected script was working fine,

for the html checbox code
image

1 Like

So does mean I need to create my checkboxes in an HTML window instead of using the out-of-the box checkbox element?

Yes. But it won’t be Bubble.io element

You can check my code that works with Bubble.io. Seem like i made it work. Check it.