简体   繁体   中英

Adobe Acrobat Required Radio Buttons Javascript

This is an Adobe Acrobat DC question. I'm working on the Javascript area and so I am hoping this is the place.

Currently creating an application form where there are "Yes" or "No" answers (using radio buttons). I want them to be required to answer but for some reason, when using the required option (outlined below) it still states that the other radio button needs to be checked. I checked and they are in the same group.

  1. I'd like to have the form require either Yes or No to be selected but not both. I've used the required selection under Properties>General. However, it is still requiring both to be checked even though they are in the same group.

I've read several js scripts but they don't seem to fit these needs as it seems to be too simple.

  1. Also, on another part of the form, if the applicant marks "Yes" I'd like a text box then be required (to explain why). So, first require a "Yes" or "No" if "Yes" then require "Textbox1"

If at all possible, if the applicant hasn't selected an option in the required radio button group, have the group display a message "Select at least one option"

The closest I could find to #2 is, I believe:

if (event.target.value == "Three") {

    this.getField("Text Field 1").required = false;

}

For #3 I believe it is similar to:

<script> 
  function validateForm() {   
     var x = document.forms["myForm"]["radioGroupName"].value;   
     if (x == "") {   
        document.getElementById("message").innerHTML = "Select atleast one option";    
     }
   }

</script>

Any assistance would be greatly appreciated. Thank you.

PS Here are a couple photos that I hope will convey what I am trying to express better than I have above. In the next photo you can see they are all in the same group (radio buttons) and they are all required: Adobe Acrobat In Editor Mode

And this next is when I am trying to fill out the form as a user using reader. It shows that the other radio buttons are also required even though they are in the same group: Adobe Reader As A User

I have been offline for some time… anyway…

A very first question is whether you did have a look at the Acrobat JavaScript documentation, in particular the section about required property, and the features of radio buttons in general.

If so, it would be obvious that the example shown for #3 is NOT Acrobat JavaScript, and would not work at all in your form. It would also have become very clear that radio buttons are mutually exclusive by design.

In order to make a field required, you actually are very close with the code snippet for #2, only that the required property of the referred field would be true (according to your requirement). However, that code snipped lacks the "else" path, where the required property would get reset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM