Skip to main content
Participating Frequently
April 28, 2021
Answered

Making a field required if a radio button or check box is selected when using a validation button

  • April 28, 2021
  • 1 reply
  • 10606 views

Hi

I've created a pdf form which has a validate button to check that certain required fields are filled in. 

I want to make an additional field (lump sum) required as part of the validation, but only if option 3 has been selected as the radio button. For option 1 and 2 it is not required.

I also want to make an additional field (AVC amount) required if a check box (Option B) is ticked. 

This is what I currently have which is working but what do I need to add for the above to work?

 

Thank you

 

if (

this.getField("Partnership status").value=="Off"||

this.getField("Question one").value=="Off"||

this.getField("Question two").value=="Off"||

this.getField("Question three").value=="Off"||

this.getField("Question four").value=="Off"||

this.getField("Question five").value=="Off"||

this.getField("Question six").value=="Off"||

this.getField("Declaration confirmation").value=="Off"||

this.getField("Date of event").value==""&& this.getField("Date of event").required==true||

{app.alert("Please complete all required fields which are highlighted in red.")}

This topic has been closed for replies.
Correct answer Nesa Nurani

Hi, thanks but that hasn't worked. I've copied the full code below if you could help please? Thank you so much.

if (
this.getField("Full name").value==""|| this.getField("Date of birth").value==""||
this.getField("Daytime phone number").value==""||
this.getField("Confirmation details correct").value=="Off"||
this.getField("Lump sum choices").value=="Off"||
this.getField("Bank name").value==""||
this.getField("Account name").value==""||
this.getField("Sort code (6 numbers)").value==""||
this.getField("Account number").value==""||
this.getField("Previous pension").value=="Off"||
this.getField("Partnership status").value=="Off"||
this.getField("Question one").value=="Off"||
this.getField("Question two").value=="Off"||
this.getField("Question three").value=="Off"||
this.getField("Question four").value=="Off"||
this.getField("Question five").value=="Off"||
this.getField("Question six").value=="Off"||
this.getField("Declaration confirmation").value=="Off"||
(this.getField("Option B").valueAsString != "Off" && this.getField("AVC fund amount").value == "")||
(this.getField("Lump sum choices").valueAsString == "Option 3 Converting some pension to lump sum" && this.getField("lump sum amount").value == "")
this.getfield("Date of event").value==""&& this.field("Date of event").required==true))
{app.alert("Please complete all required fields which are highlighted in red.")}


Try like this:

if (
this.getField("Full name").value==""|| this.getField("Date of birth").value==""||
this.getField("Daytime phone number").value==""||
this.getField("Confirmation details correct").value=="Off"||
this.getField("Lump sum choices").value=="Off"||
this.getField("Bank name").value==""||
this.getField("Account name").value==""||
this.getField("Sort code (6 numbers)").value==""||
this.getField("Account number").value==""||
this.getField("Previous pension").value=="Off"||
this.getField("Partnership status").value=="Off"||
this.getField("Question one").value=="Off"||
this.getField("Question two").value=="Off"||
this.getField("Question three").value=="Off"||
this.getField("Question four").value=="Off"||
this.getField("Question five").value=="Off"||
this.getField("Question six").value=="Off"||
this.getField("Declaration confirmation").value=="Off"||
(this.getField("Option B").valueAsString != "Off" && this.getField("AVC fund amount").value == "")||
(this.getField("Lump sum choices").valueAsString == "Option 3 Converting some pension to lump sum" && this.getField("lump sum amount").value == "")||
(this.getfield("Date of event").value==""&& this.field("Date of event").required==true))
{app.alert("Please complete all required fields which are highlighted in red.")}

1 reply

Inspiring
April 28, 2021

There is no way above code works.

You have error at the end and you are just making conditions, you are not doing anything with it.

Participating Frequently
April 28, 2021

Hi

I only know a limited amount about Javascript which is why I have asked for help above in adding to it, so I'm not sure what error you are referring to but the script as it currently is, is working. If any of the fields listed above (which have been ticked as required as they are always required) have been left blank/no button selected and the validate button on the pdf is pressed then the message appears as a popup. This is all I need it to do, but I need to add the fields mentioned above which are only required depending on other answers.

The final part of the script I have already had help with as this was based on the field only being required if one of 5 of 7 options was selected. I have tried to adapt this for what I need to add but have not had any luck in being able to add the additional fields that I mention above. I would appreciate any advice on being able to add these. Thank you.

Inspiring
April 28, 2021

Try paste code above in your field and then try exit javascript editor.