Expand my Community achievements bar.

SOLVED

Radio Buttons

Avatar

Level 4

I have a radio button list of

'a' has value of 1, b=2, c=3, d=4, e=5

If  'a' is selected, I want its value of 1 to be assigned to X.

If  'b' is selected, I want its value of 2 to be assigned to X.

How do I code the above using

i)  IF syntax

ii) the switch { case   syntax?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi Iakov,

If syntax:

if (this.rawValue=='1') TextField1.rawValue="1";
if (this.rawValue=='2') TextField1.rawValue="2";
if (this.rawValue=='3') TextField1.rawValue="3";
if (this.rawValue=='4') TextField1.rawValue="4";
if (this.rawValue=='5') TextField1.rawValue="5";

Switch syntax:

switch (this.rawValue)

{
case '1' :
    TextField1.rawValue="1";
    break;
case '2' :
    TextField1.rawValue="2";
    break;
  case '3' :
    TextField1.rawValue="3";
    break;
case '4' :
    TextField1.rawValue="4";
    break;
case '5' :
    TextField1.rawValue="5";
    break;

}

But the most elegant way to do it is :TextField1.rawValue=this.rawValue;

Yan.

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

Hi Iakov,

If syntax:

if (this.rawValue=='1') TextField1.rawValue="1";
if (this.rawValue=='2') TextField1.rawValue="2";
if (this.rawValue=='3') TextField1.rawValue="3";
if (this.rawValue=='4') TextField1.rawValue="4";
if (this.rawValue=='5') TextField1.rawValue="5";

Switch syntax:

switch (this.rawValue)

{
case '1' :
    TextField1.rawValue="1";
    break;
case '2' :
    TextField1.rawValue="2";
    break;
  case '3' :
    TextField1.rawValue="3";
    break;
case '4' :
    TextField1.rawValue="4";
    break;
case '5' :
    TextField1.rawValue="5";
    break;

}

But the most elegant way to do it is :TextField1.rawValue=this.rawValue;

Yan.

Avatar

Level 4

>  But the most elegant way to do it is :TextField1.rawValue=this.rawValue;

Hahahaha  :-)

I had no idea.  I thought one had to test for each radio button value, which was why I asked for IF and SWITCH syntax.

I tried your elegant suggestion and it worked elegantly.

Thank you! 

Haha.

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