JavaScript validation
Copy link to clipboard
Copied
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!!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
I did... not working . I'm attaching the document here...
Copy link to clipboard
Copied
Move script to calculate tab.
Copy link to clipboard
Copied
omg tk u so much!!! It is working!

