Expand my Community achievements bar.

SOLVED

How do I Programatically Check or Uncheck a Check Box

Avatar

Former Community Member

Hello,

Could anyone help me with the code necessary to uncheck or check a checkbox on a form?  Let's say there is a button, and I want that button when clicked to automatically check a check box.  My actual goal is to have code that loops through all the checkboxes on the form, if they are checked it unchecks them and rechecks them, if they are unchecked it leaves them alone.

Thank you

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

if (checkBox.rawValue != 1){

     checkBox.rawValue = 1;

}

That should check the box if it isn't.  Make sure that if you changed your on/off values, though, that your script reflects that.  Setting the rawValue to 1 assumes that your on value is the default 1 and your off value is the default 0.

Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com

View solution in original post

1 Reply

Avatar

Correct answer by
Former Community Member

if (checkBox.rawValue != 1){

     checkBox.rawValue = 1;

}

That should check the box if it isn't.  Make sure that if you changed your on/off values, though, that your script reflects that.  Setting the rawValue to 1 assumes that your on value is the default 1 and your off value is the default 0.

Ryan D. Lunka

Cardinal Solutions Group

rlunka@cardinalsolutions.com

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----