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

dropdown selection auto-selecting checkbox

Contributor ,
May 29, 2023 May 29, 2023

Know this subject has been answered many times, because I've tried all the solutions listed, even tweaking them here and there, running as 'mouse-up' script, Nesa's validation script, and inserting into an existing custom calculation script, all in the dropdown field- and all to no avail. In short, I have a dropdown with four choices and their export values 1, 2, 3, 4 respectively. I have two target checkboxes (Box1, Box2) on the next page of the form. Dropdown selections 1, 2, 3 need to "Check" Box1, while Dropdown selection 4 needs to "Check" Box2. The following custom validation script worked, but when the dropdown selection was changed to another selection, nothing changes, stays the same. I need the ability to "Check/Uncheck" Box1 and Box2 when switching the Dropdown selections to reflect the right association between the dropdown selection and the "checking/unchecking" of the Boxes 1, 2.. Spent a day and half on this- so really need some guidance on detangling what's left of my mind! Thanks in advance!!

TOPICS
How to , JavaScript
613
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
Community Expert ,
May 29, 2023 May 29, 2023

What validation script does you use?

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
Community Expert ,
May 29, 2023 May 29, 2023

Remove other scripts (if you have any) and use this in dropdown field as 'Custom calculation script':

this.getField("Box1").checkThisBox(0, event.value == 1 || event.value == 2 || event.value == 3 ? true : false);
this.getField("Box2").checkThisBox(0, event.value == 4 ? true : false);

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
Contributor ,
May 30, 2023 May 30, 2023

Thank you Bernd and Nesa for your replies. Nesa, the custom calculation script that you provided works as intended, but I'm still experiencing not being able to switch between dropdown selections and their target Box. Both Boxes 1 and 2 remain "checked" when swapping between dropdown selections, rather than  dropdown selections 1 - 3 checking Box 1 whilst unchecking Box 2 if its dropdown selection (4) was mistakenly selected by the user and subsequently changed, and vice versa. Is this possible? Also, I had a custom calculation script to show/hide other unrelated textfields and for this I had each dropdown selection using if/else statement to show/hide these text fields. I mentioned this b/c I modified your 1st statement by separating the individual dropdown selections into separate this.getField ... statements, and inserted each one into their resective 'if' statements separated by the curly brackets {}. Don't know if this adversely affected your original solution, but that's been plaguing me now for some time. Thank you both again for your guidance, not just here but for all your  posts- extremely helpful!!!

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
Contributor ,
Jun 01, 2023 Jun 01, 2023
LATEST

I plugged in your scripts, but now the hide/show of text fields doesn't work and still neither do the checkbocxes- I know I'm doing something wrong, just unsure if it's ignorance or stupidity on my part? Assistance really appreciated!

 

if (event.value == "Choice1") {

this.getField("TextField1").display = display.visible;

this.getField("TextField2").display = display.hidden;

this.getField("TextField3").display = display.hidden;

this.getField("TextField4").display = display.hidden;

this.getField("CkBx1").checkThisBox(0, event.value == "Choice1" ? true : false);
}

else if (event.value == "Choice3") {

this.getField("TextField1").display = display.hidden;

this.getField("TextField2").display = display.visible;

this.getField("TextField3").display = display.visible;

this.getField("TextField4").display = display.hidden;
this.getField("CkBx1").checkThisBox(0, event.value == "Choice2" ? true : false);
}

else if (event.value == "Choice2") {

this.getField("TextField1").display = display.visible;

this.getField("TextField2").display = display.hidden;

this.getField("TextField3").display = display.hidden;

this.getField("TextField4").display = display.visible;

this.getField("CkBx2").checkThisBox(0, event.value == "Choice2" ? true : false);
}

else if (event.value == "Choice4") {

this.getField("TextField1").display = display.visible;

this.getField("TextField2").display = display.visible;

this.getField("TextField3").display = display.visible;

this.getField("TextField4").display = display.hidden;

this.getField("CkBxMV84990").checkThisBox(0, event.value == "Choice4" ? true : false);

}

else {

this.getField("TextField1").display = display.hidden;

this.getField("TextField2").display = display.hidden;

this.getField("TextField3").display = display.hidden;

this.getField("TextField4").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