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

Javascript for radio button to activate or deactivate text fields

Community Beginner ,
Aug 28, 2023 Aug 28, 2023

I have a form with two connected radio buttons i'll like to connect each to specific text fields such that when one radio button is selected, it activates/deactivates specific text fields. The code i'm currently using does not work well during testing. I noticed that when I select one button, it works but when I change my mind and select the other button instead, it deactivates all the fields for both buttons. I used my clear form button to reset the form but the text fields remain deactivated even though no radio button is selected.

 

Here's the code I used and just interchanged the value and text fields for the substitute button:

 

if(this.getField('Shelter cost').value == 'renter')

{this.getField('mortgage frequency').readonly = true;

this.getField('monthly mortgage').readonly = true;

this.getField('biweekly mortgage').readonly = true;

this.getField('annual mortgage').readonly = true;

this.getField('annual mortgage 2').readonly = true;

this.getField('Property tax').readonly = true;}

else

{this.getField('mortgage frequency').readonly = false;

this.getField('mortgage frequency').value = "";

this.getField('monthly mortgage').readonly = false;

this.getField('monthly mortgage').value = "";

this.getField('biweekly mortgage').readonly = false;

this.getField('biweekly mortgage').value = "";

this.getField('annual mortgage').readonly = false;

this.getField('annual mortgage').value = "";

this.getField('annual mortgage 2').readonly = false;

this.getField('annual mortgage 2').value = "";

this.getField('Property tax').readonly = false;

this.getField('Property tax').value = "";}

TOPICS
JavaScript , PDF , PDF forms
1.3K
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 ,
Aug 28, 2023 Aug 28, 2023

Where did you place the code?

Do both script affect the same fields? If so, they will conflict with one another. You will need to create a single script that covers all options.

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 Beginner ,
Aug 28, 2023 Aug 28, 2023

I placed the code in the Actions panel of the radio button with the trigger "Mouse Up" and action "Run a Javascript". I'm new to coding so it's all still kinda confusing for me. I want users to choose between being a renter or a homeowner. If they select the renter radio button, the text fields for mortgage information will be deactivated and they'll only be able to complete the fields for rent information but if they select the button for homeowner, they'll only be able to complete the text fields for mortgage information. What's the best way to go about it?

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 ,
Aug 29, 2023 Aug 29, 2023

OK, the issue is that the Clear Form command does not trigger this code, then.

You'll need to add a separate script to your Reset Form button to reset the readonly property of the fields to its default state.

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 Beginner ,
Aug 29, 2023 Aug 29, 2023

Ok, can you please give me the script I'll add to the Reset form button?

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 ,
Aug 29, 2023 Aug 29, 2023
LATEST

Basically just copy the code in the "else" part of the if-condition in your script.

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