Copy link to clipboard
Copied
Is it possible to make a field required depending on how a previous radio button or if a check box was clicked?
Thanks,
Kim
Hi Kim,
You can apply the following script on the "Mouse Up" Action of the radio buttons.
Suppose you have 2 radio buttons A and B and you want to make the Text field (Text2) required when A is selected, you can add "Run a JavaScript" action on the
Mouse Up trigger of Button A:
if(event.target.value == "A") {
this.getField("Text2").required = true;
}
Mouse Up trigger of Button B:
if(event.target.value == "B") {
this.getField("Text2").required = false;
}
Please check this form for more.
Regards,
BR
Copy link to clipboard
Copied
Hi Kim,
You can apply the following script on the "Mouse Up" Action of the radio buttons.
Suppose you have 2 radio buttons A and B and you want to make the Text field (Text2) required when A is selected, you can add "Run a JavaScript" action on the
Mouse Up trigger of Button A:
if(event.target.value == "A") {
this.getField("Text2").required = true;
}
Mouse Up trigger of Button B:
if(event.target.value == "B") {
this.getField("Text2").required = false;
}
Please check this form for more.
Regards,
BR
Copy link to clipboard
Copied
BR,
Thank you so much for the incredibly quick reply. That worked perfectly for my radio buttons, but I have one checkbox that if it is checked, the field below is required. It does work, but if the person changes their mind and un-checks it, the option (which is a radio button) still remains required after unchecking.
Thank you again for your time.
Kim
Copy link to clipboard
Copied
Hi Kim,
If I understood your query correctly, you have a check box, and then 2 radio buttons, if you check the check box, you should be able to make a choice between the 2 radio buttons, and when you select a particular radio button, a text field should become required. On un-checking the check box, the field should be optional, and the radio buttons should not have any option selected. (Please correct me if I got it wrong)
To do this, you can add this Java script on the "Mouse Up" trigger of the CheckBox:
if(event.target.value == "Yes") {
this.getField("Group1").value = "A";
this.getField("Text2").required = true;
}
else
{
this.getField("Group1").value = "";
this.getField("Text2").required = false;
}
Keep the previous script (on the radio buttons) untouched.
Please see this form.
BR
Copy link to clipboard
Copied
BR,
I can't thank you enough for the quick responses. Both worked like a charm. Can I use the same formula whether I am going from a checkbox to radio button or radio button to text field, or radio button to checkbox?
This is EXACTLY what I needed. Just out of curiosity... could I have found this somewhere within the knowledge database (meaning is that what you did) or did you just write it? I've made if, then, else statements before but it has been years. I guess I would just like to figure out if you found it somewhere so I wouldn't have to bother anyone again if I had another question.
You ROCK!!
Kim
Copy link to clipboard
Copied
Hi Kim,
It's great that the scripts worked perfectly for you!!
If you want to use it for a radio button to check box, you could use the same formula, just keep in mind that for radio buttons we use (this.getField("Group1").value = "A";) and for check boxes, we use (this.getField("Checkbox1").value = "Yes";). If you are using the correct syntax, you can use the same formula.
I wrote this code according to your requirements, and you can find the basic Acrobat JavaScript guide at: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/Acro6JSGuide.pdf
and you can also refer to : http://www.planetpdf.com/planetpdf/pdfs/jkingFormsTut.pdf
BR
Copy link to clipboard
Copied
brawal wrote:
Hi Kim,
It's great that the scripts worked perfectly for you!!
If you want to use it for a radio button to check box, you could use the same formula, just keep in mind that for radio buttons we use (this.getField("Group1").value = "A";) and for check boxes, we use (this.getField("Checkbox1").value = "Yes";). If you are using the correct syntax, you can use the same formula.
I wrote this code according to your requirements, and you can find the basic Acrobat JavaScript guide at: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/Acro6JSGuide.pdf
and you can also refer to : http://www.planetpdf.com/planetpdf/pdfs/jkingFormsTut.pdf
BR
brawal,
You were kind enough to help me before and I have one more issue with conditional boxes that I can't seem to find a way to do. I have looked over the links you sent me and coulnt find an answer. I thought maybe it is not possible, but I was told it is with scripting.
I have a question with 5 possible checkbox options. Here is the question.
Do you have any of the following? (Client privacy will be protected as per HIPAA laws):
[___] None [___] Hep B [___] Hep C [___] HIV
[___] Other - Specify ___________________________________________________
I need to make this required but also give them the ability to check more than one option. I was told the only way to do this is to make each checkbox an individual item. But if that is the case, they cannot be required. Basically, I need to make sure that at least one of the five options are selected and if NONE is selected, then the others should be blank. Does that make sense? Is this even possible?
Also, I can see me doing more of these if, then, else statements but I didnt see anything about how to write these in the links you sent me. Do you have any suggestions on learning how to do this?
Thank you again for everything!
Kim
Find more inspiration, events, and resources on the new Adobe Community
Explore Now