Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript when radio button is selected to show/hide fields based on another group radio button

New Here ,
Sep 10, 2020 Sep 10, 2020

Trying to get this working. I have 2 groups of radio buttons:

Group1

  • Yes
  • No

Group2

  • SIP
  • CPBX

 

When you select the "Yes" or "No radio button from Group 1 I need to hide or display certain text fields, i grouped all of the fields I am showing/hiding.

 

Here is my javascript code for the "Yes" button, I have it set to onMouseUp for the event. When I run it I get nothing, I think radio1 is null. If I substitute radio1.value in my 'if' statements with this.getField("Group2").value I get a "Get not possible, invalid or unknown." in the javascript console.

 

var radio1 = this.getField("Group2").value;

if(radio1.value == "SIP"){
    getField("SIP").display.visible;
    getField("SIPEMER").display.hidden;
    getField("CPBX").display.hidden;
    getField("CPBXEMER").display.hidden;
}

if(radio1.value == "CPBX"){
    getField("SIP").display.hidden;
    getField("SIPEMER").display.hidden;
    getField("CPBX").display.visible;
    getField("CPBXEMER").display.hidden;
}

 

Any help is appreciated, I tried searching as much as I could and could not locate anything that would help me. It seems that I am setting my radio1 correctly since it is Group2 that would have the value of "SIP" or "CPBX" based on which radio button is selected so I am not sure where I am going wrong

TOPICS
How to
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
New Here ,
Sep 10, 2020 Sep 10, 2020
LATEST

I am daft haha, so the get method that was throwing the errors was the getField nested in the "if" statements. I needed to adjust them to be .display = display.visible;.

My final javascript code ended up being:

 

var radio1 = this.getField("Group2").value;


if(radio1 == 1){
getField("SIP").display = display.visible;
getField("SIPEMER").display = display.hidden;
getField("CPBX").display = display.hidden;
getField("CPBXEMER").display = display.hidden;
} else if(radio1 == 2){
getField("SIP").display = display.hidden;
getField("SIPEMER").display = display.hidden;
getField("CPBX").display = display.visible;
getField("CPBXEMER").display = display.hidden;
}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 10, 2020 Sep 10, 2020
LATEST

I am daft haha, so the get method that was throwing the errors was the getField nested in the "if" statements. I needed to adjust them to be .display = display.visible;.

My final javascript code ended up being:

 

var radio1 = this.getField("Group2").value;


if(radio1 == 1){
getField("SIP").display = display.visible;
getField("SIPEMER").display = display.hidden;
getField("CPBX").display = display.hidden;
getField("CPBXEMER").display = display.hidden;
} else if(radio1 == 2){
getField("SIP").display = display.hidden;
getField("SIPEMER").display = display.hidden;
getField("CPBX").display = display.visible;
getField("CPBXEMER").display = display.hidden;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines