Highlighted

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

New Here ,
Sep 10, 2020

Copy link to clipboard

Copied

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

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;
}
TOPICS
How to

Views

40

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

New Here ,
Sep 10, 2020

Copy link to clipboard

Copied

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

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;
}
TOPICS
How to

Views

41

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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;
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 10, 2020 0