Expand my Community achievements bar.

SOLVED

Check box if numeric field equals set value

Avatar

Level 2

Newbie needs help!!

I am trying to write a script to check a box, but only after a numeric field adds up to "4"

If you look at my attached file, "Student 1" has four check boxes (Pre-Course Skills, course roster, etc.).  Each time those boxes are checked/unchecked, the numeric field + or - 1 from the rawValue.  The script that I'm having problems with is on the check box next to Student 1 ...

Here's the "calculate" script attached to that check box:

if (stu1_results.rawValue == 4) {

     CheckBox_stu1.rawValue == true; // Check the box

else {

     CheckBox_stu1.rawValue == false; // Un-check the box

}

Any advice would be awesome!!

Mike Schaefer

(blinkyguy)

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

There were two things wrong with your code. Logically it was fine but you were mixing up an assign,ent statement and a comparison. In an if statement if you wantt o compare two values you need  two equal signs. If you want to assign one value to another you need a single equal sign. That was number one. NUmber two is when you assign the value of the checkbox. The on/off values are 1/0 not true/false. So you can either modify your code to assign a 1/0 value instead of true/false or modfiy the checkbox to have true/false as its values instead of 1/0.

The code shoudl look like this:

if (stu1_results.rawValue == 4){

  CheckBox_stu1.rawValue =1;

} else {

  CheckBox_stu1.rawValue = 0;

}

Paul

View solution in original post

6 Replies

Avatar

Level 7

Try:

if (stu1_results.rawValue == 4) {

     CheckBox_stu1.rawValue = true; // Check the box

else {

     CheckBox_stu1.rawValue = false; // Un-check the box

}

Avatar

Level 2

Unfortunately, the suggestion did not work ...

I believe your example was missing a " { " ... here's what I tried and still a no-go:

if (stu1_results.rawValue == 4) {

     CheckBox_stu1.rawValue = true; // Check box

     }

else {

     CheckBox_stu1.rawValue = false; // Un-check box

}

Thanks,

Mike S.

Avatar

Level 2

I now have it working by doing the following:

1 - Changed from "JavaScript" to "FormCalc" language

2 - Changed the script to look like:

if (stu1_results.rawValue == 4) then

     CheckBox_stu1.rawValue = 1; // Check box

else

     CheckBox_stu1.rawValue = 0; // Un-Check box

endif

For anyone out there, I would love it if someone could tell me how to properly script the above in JavaScript, as that is what I am more familiar with.

Thanks,
Mike S.

Avatar

Correct answer by
Former Community Member

There were two things wrong with your code. Logically it was fine but you were mixing up an assign,ent statement and a comparison. In an if statement if you wantt o compare two values you need  two equal signs. If you want to assign one value to another you need a single equal sign. That was number one. NUmber two is when you assign the value of the checkbox. The on/off values are 1/0 not true/false. So you can either modify your code to assign a 1/0 value instead of true/false or modfiy the checkbox to have true/false as its values instead of 1/0.

The code shoudl look like this:

if (stu1_results.rawValue == 4){

  CheckBox_stu1.rawValue =1;

} else {

  CheckBox_stu1.rawValue = 0;

}

Paul

Avatar

Level 2

Thank you all for your help.  Tried out the JavaScript and it worked like a charm!

Always the best source for help!!

Mike S.

Avatar

Former Community Member

Hi Paul,

I'm having a similar problem but your suggestion didn't work for me, at least not right away. I had to click around on the form to make the check box tic. Basically, I used:

if (JhammerSatTotal.rawValue <=80){
  JhammerPassed.rawValue =1;

} else {

  JhammerPassed.rawValue =0;

}

Essentially I have two boxes: one if they passed and one if they failed. So, if the value of the points awarded is greater than or equal to 80, then the 'passed' box tics. I added the less than version to the 'failed' box. They only seem to tic if I click on the JhammerSatTotal cell, then away, then back again. Is this just a quirk of the program or is there a way for it to be more responsive?

Thanks!

~Laura

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] ----