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

Java script Help!

New Here ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Hello all,

 

I have 3 check marks, when I check one I want the others to be read only or hidden, I also have 11 fields that need to be read only or hidden depending on which check mark is selected. Knowledge of coding is less than basic 😩. I appreciate anyones help, thank you!

TOPICS
JavaScript

Views

365

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
community guidelines
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Let's say your checkboxes are named "check1","check2","check3".

I would use hidden text field with custom calculation script:

var c1 = this.getField("check1");
var c2 = this.getField("check2");
var c3 = this.getField("check3");
//Set "check1" to readonly if "check2" or "check3" are checked
c1.readonly = c2.valueAsString != "Off" || c3.valueAsString != "Off" ? true : false;

//Set "check2" to readonly if "check1" or "check3" are checked
c2.readonly = c1.valueAsString != "Off" || c3.valueAsString != "Off" ? true : false;

//Set "check3" to readonly if "check1" or "check2" are checked
c3.readonly = c1.valueAsString != "Off" || c2.valueAsString != "Off" ? true : false;

To include text fields, you need to tell us field names and what are conditions when should they be hidden/read-only.

Votes

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
community guidelines
New Here ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

Thank you so much for your reply and assistance. In order for this to work do I add action show/hide? Meaning for checkbox 1 add show/hide for checkbox 2 and 3 then add the Java script? The fields I need to show hide are if checkbox 1 is selected hide Field 4-field 11, checkbox 2 hide field 1-4 & 8-11, and checkbox 3 hide field 1-8. Or would it make more sense to instead of hiding the field make them visible based on which checkbox is selected, i.e if checkbox 1 is selected make fields 1-4 visible, checkbox 2 selected make fields 5-8 visible, and when checkbox 3 is selected make fields 9-11 visible? Thank you for all your help on this! 

Votes

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
community guidelines
Community Expert ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

Add this to the previous script I gave you:

this.getField("field1").display = c1.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field2").display = c1.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field3").display = c1.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field4").display = c1.valueAsString == "Off" ? display.hidden : display.visible;

this.getField("field5").display = c2.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field6").display = c2.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field7").display = c2.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field8").display = c2.valueAsString == "Off" ? display.hidden : display.visible;

this.getField("field9").display = c3.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field10").display = c3.valueAsString == "Off" ? display.hidden : display.visible;
this.getField("field11").display = c3.valueAsString == "Off" ? display.hidden : display.visible;

Votes

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
community guidelines
New Here ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

Thank you! So I added a hidden text field and added a custom calculation script where I pasted both scripts you provided (thank you so much), but when I preview form it doesn't run the script. Is there something I am missing? Thank you for all you help!

Votes

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
community guidelines
Community Expert ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

LATEST

Share your file. 

Votes

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
community guidelines
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

++ Adding to the discussion,

 

See if this recent discussion helps:

 

 

There is a good link to an article that explains how checkboxes and radio button widgets work .

 

In addition , note the example script; which you can modify to meet your requirement.

 

Votes

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
community guidelines