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

I need help making form boxes stay red

New Here ,
Oct 29, 2024 Oct 29, 2024

Hey,

 

Apologies in advance - I'm an old dog trying to learn new tricks.

 

I've created a questionnaire using Prepare form, and there are 17 questions, each with a pair of Radio Buttons. I've tried to add a javascript to each one that turns the 'No' option to red if it's selected. I've managed that, but then when any subsequent options are selected, the red disappears and it just returns to transparent. Does anyone know how I can change my code to keep it red? Here's the code I plagiarised from another forum...

 

// Loop through questions q1 to q17 and apply the color change
for (var i = 1; i <= 17; i++) {
// Define the current radio button group name
var fieldName = "q" + i;

// Get the field object
var field = this.getField(fieldName);

// Check if Choice2 is selected
if (field.value === "Choice2") {
// Change text color of Choice2 to red
field.textColor = color.red;
}
}

 

Can anyone help? I just have no idea where to start.

 

Thank you so much!

TOPICS
JavaScript , PDF , PDF forms
500
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
Community Expert ,
Oct 29, 2024 Oct 29, 2024

This code edits all the fields, though, not just the one you pasted it under. You need to either modify it to edit a single field at a time (you can get access to it via event.target), or place a single copy of it under the Calculation event of some text field.

Also, it will not work if your fields are named "Q1", "Q2", as it references fields called "q1", "q2", etc., and JS is case-sensitive.

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
Community Expert ,
Oct 29, 2024 Oct 29, 2024

Where did you place this code? What triggers it?
Also, you should add an else-clause to change the field's color back to Black (or whatever other color) if "Choice2" is not ticked.

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 ,
Oct 29, 2024 Oct 29, 2024

Sorry, I should've said that...

 

Under 'General' I have each group named Q1, Q2, Q3 etc. And then in 'Radio Button Choice' under 'Options', I have 'Choice1' and 'Choice2' for each group.

 

Then under 'Actions', I added a Mouse Up action to run JavaScript, and pasted this code for each individual 'Choice2'

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 ,
Oct 29, 2024 Oct 29, 2024

This code edits all the fields, though, not just the one you pasted it under. You need to either modify it to edit a single field at a time (you can get access to it via event.target), or place a single copy of it under the Calculation event of some text field.

Also, it will not work if your fields are named "Q1", "Q2", as it references fields called "q1", "q2", etc., and JS is case-sensitive.

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 ,
Oct 29, 2024 Oct 29, 2024
LATEST

Thank you for your help! It works perfectly now. Amazing, thank you!

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