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

JavaScript validation

Community Beginner ,
Apr 18, 2022 Apr 18, 2022

I have a form with a radio button and I'd like to make some text fields required if that option is checked...

I added the following snippet to my text field but I don't really know ho to test it lol

 

var insuranceField = this.getField("insurance").value;
var policyField = this.getField("policy").value;
if( insuranceField == "insuranceBill" && policyField == ""){
app.alert("Policy Holder Name is required");
}

 

Can anyone help me with this? Tks!!

TOPICS
PDF forms
1.5K
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 ,
Apr 18, 2022 Apr 18, 2022

Use this script as a Calculation script in the Text fields:

 

if (this.getField("CHECKBOX1").value != "Off") {event.target.required = true;}
else {event.target.required = false;}


Acrobate du PDF, InDesigner et Photoshoptographe
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 ,
Apr 18, 2022 Apr 18, 2022

JR tk u for responding.

 

I can't use != "OFF" because they can check a different radion button option so I added

 

if (this.getField("insurance").value != "insuranceBill"){
event.target.required = true;
}else {
event.target.required = false;
}

 But now the policy field has the red border on it but it doesn't go away if I select a different option in the radio 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 ,
Apr 18, 2022 Apr 18, 2022

If you select other option red circle should go away with that script, but you have problem if neither choices is selected field will be required.

Try changing first line like this:

if (this.getField("insurance").value != "insuranceBill" && this.getField("insurance").value != "Off"){

This should make field required when other choices are selected.

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 ,
Apr 18, 2022 Apr 18, 2022

Nesa,

 

I just noticed I checked the option "Required" by accident, that's why the red border didn't go away... so now I just added the initial snippet and there is no red border if I select the radio option I want to make policy field required or even the other options, like nothing is changing.

 

Screen Shot 2022-04-18 at 1.46.07 PM.pngexpand image

So the first 3 radios are names as "insurance" and the 3rd option has as a value "insuranceBill"

 

policy text field should be required if insuraceBill is checked.

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 ,
Apr 18, 2022 Apr 18, 2022

If you want it required when "insuranceBill" is checked then change  != "insuranceBill" to == "insuranceBill".

This should do the trick:

event.target.required = this.getField("insurance").value == "insuranceBill" ? 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
Community Beginner ,
Apr 18, 2022 Apr 18, 2022

I did... not working . I'm attaching the document here...

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 ,
Apr 18, 2022 Apr 18, 2022

Move script to calculate tab.

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 ,
Apr 18, 2022 Apr 18, 2022
LATEST

omg tk u so much!!! It is working!

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