Expand my Community achievements bar.

SOLVED

"If" statement issue

Avatar

Level 3

I am having issues with my script:

Checkbox is named - CO14

TextField  is named - HQName

TextField is named - HQNumber

I would like the persons name Jane Doe to appear in the textfield HQName

"                         "       number 222-231-4567 to apear the textfield  HQNumber

I would also like for there name to disappear once the check box is deselected

This is what I have as my script now and of course it is not working the only thing that happens is Jane Doe name appears.

if

(CO14.rawValue == 1)

}

HQName.rawValue = "Jane Doe"; HQNumber.rawValue = 222-231-4567 + "\n";

}

Any help is appreciated.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Because this is a checkbox and it only has two values, there is no need to check for teh 2nd value. If it is not 1 it must be 0. You can just add an else section that will blank out those fields:

if

(CO14.rawValue == 1)

HQName.rawValue = "Jane Doe"; HQNumber.rawValue = 222-231-4567 + "\n";

} else {

HQName.rawValue = "";HQNumber.rawValue = "";

}

Hope that helps

Paul

{

View solution in original post

5 Replies

Avatar

Former Community Member

You need to open your curly brace instead of closing it to begin with:

if

(CO14.rawValue == 1)

{

HQName.rawValue = "Jane Doe"; HQNumber.rawValue = "222-231-4567" + "\n";

}

Paul

Avatar

Level 10

Hi,

This should work:

if (CO14.rawValue == 1) {

     HQName.rawValue = "Jane Doe";

     HQNumber.rawValue = "222-231-4567" + "\n";

}

The telephone number also needs to be in quotation marks. The first curly brackets was the wrong one/way, but that could have been a typo in the post.

Hope that helps,

Niall

Avatar

Level 3

If I deselect the checkbox what script is used to make the name and number disappear?

Avatar

Correct answer by
Former Community Member

Because this is a checkbox and it only has two values, there is no need to check for teh 2nd value. If it is not 1 it must be 0. You can just add an else section that will blank out those fields:

if

(CO14.rawValue == 1)

HQName.rawValue = "Jane Doe"; HQNumber.rawValue = 222-231-4567 + "\n";

} else {

HQName.rawValue = "";HQNumber.rawValue = "";

}

Hope that helps

Paul

{

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