JavaScript Check if checkbox checked
Application Type
Mobile, Reactive
Service Studio Version
11.10.16 (Build 40208)
Platform Version
11.11.2 (Build 29094)

I am brand new to outsystems. I have 23 years development experience but none with outsystems so I am asking for a plain simple English answer. I have tried document.getElementsByName(“Checkbox5”) which is the name the checkbox had in properties. I have also tried with tick marks instead of double quotes. But I am unable to do a check to see if the checkbox is checked or not so I can apply some logic. I have this ad an OnChange event. I have an alert in the js file. The alert shows up. But I am stumped for the correct syntax to get what I want. Thanks. 

mvp_badge
MVP

Hi Judge,

Ideally you don't need JS to check if checkbox is checked or not. You can check the value of the variable set in the your checkbox.

If it is true then it is checked else not. If you want to use this value in some logic in your JS then simplly pass the variable value as input to your JS as an input parameter.

I hope it will solve your problem. Let me know you are trying to do something else which can not be achieved with this.

Also I would recommend you to complete the reactive and mobile training first to be able to understand all the details about mobile and reactive development.

https://www.outsystems.com/training/paths/18/becoming-a-reactive-web-developer/

https://www.outsystems.com/training/paths/1/becoming-a-mobile-developer/

Unfortunately I am doing a challenge for a company as part of an interview process so time is limited. Are you saying that document.getElementsByName will not work in a js script?  That is what I am asking about and what I would like to do.  Pure and simple. A simple little JavaScript. 

Champion

Hi Judge,

I think it may not get the element using javascript. The actual element id rendered on the screen may be different if you try to query using harcoded element id

Hope it helps 

mvp_badge
MVP

Okay, if you have to do it using getElementByName only in JS then you have to use statement like this:

document.getElementsByName("Checkbox5")[0].checked

There is no difference in using double quote or single quote, it should work.

But I will still say this is not the best way to get the checkbox status, you should do this only if you are specifically asked to do it like this.

Thanks. I will give that a try. 

Since I see [0] in your code above.  Are you saying that Checkbox5 is part of an array of elements on the screen and not an individual object and that is why it can’t be accessed with just getElementsByName directly?

Hello @Judge Eagle,

If your checkbox is named 'Checkbox5' and you want to get its checked status, the following should work:

document.getElementById('Checkbox5').checked

Regards

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.