Skip to main content
Known Participant
May 31, 2020
Question

Required/unrequired dependent on tick box

  • May 31, 2020
  • 3 replies
  • 1492 views

Hi Community, (originally posted under the wrong programm, and I use Acrobats DC Standard)

I am nearly getting to the end of my form and have managed to "calculate" my way through most things or find really good help within the community. However, I am struggling with something that's probably silly, but it's bugging me. I have found a really easy way of making a field required when a radio button is selected. In the MouseUp action of the relevant button, I have entered the following Java script: this.getField ("field_name").required = event.target.value!="off". 

In all honesty I have no idea what this says except, that when this field is ticked, then the field called "field name" is showing up as required. Superb, brilliant and great. BUT and that's what I need help with. If someone changes their mind and changes the radio button selection, the field remains required but I don't want it to be. Surely it's possible to make this work with a further little bit onto that script. Anyone able to help?

This topic has been closed for replies.

3 replies

Legend
May 31, 2020

Hmm, the thing is, as a programmer, and it's very annoying but we all face it, is that computers do what we ask them to, not what we want them to. So.. you click on button 1 - there is a mouse up action - and it does something to field 1. You click on button 2 - another mouse up action - and it does something to field 2. So far so good, or at least something we should be able to fix if you tell us the names and export values of each field. But, I think you want something else to happen, and you haven't asked for it. When you click on button 2 you want to do something to field 2 - but you also want to UNDO what you did to field 1 (and perhaps 3 and 4). Nothing in your code does that.

Known Participant
May 31, 2020

You got me! But that's kind of why I said that it must be something obvious I am missing and that there's probably something that could be added on to the original script (with the correct Off that is!). Names are: I, C, D and O; as I need it for another script, the export values of each field are exactly the same. I would have thought it's something simpler like: in the event that I is ticked make field "Last_name" required. If I isn't ticked then make field "last_name" unrequired. Or - as you have asked, is it, if I is actually I, then make field "Last_name" required, otherwise don't. But how do you get an if statement in the MouseUp, does it work like any other? I have done a number of them for the rest of the form. Looking forward to learning more on this... 

Legend
May 31, 2020

Your problem is that there isn't an event for "field is ticked" and "field is unticked" (including automatically). Your event is "field is clicked with the mouse". So each field needs to check whether the box is on or off, make one field required, and make the other three fields not required. That's a lot of code to write (I know because I often find myself doing much the same sort of thing).

Bernd Alheit
Community Expert
Community Expert
May 31, 2020

Does you use a radio button or a checkbox?

Known Participant
May 31, 2020

I am using a radio button. 

Bernd Alheit
Community Expert
Community Expert
May 31, 2020

You use 2 radio buttons?

Legend
May 31, 2020

I believe the code has been copied wrong. In fact, it sets the other field as required every time you click on the check box, whether you are turning the check box on or off. The error is that "off" should have been "Off" because that’s the value a check box has when it is off. (Don’t see the difference? Capital letter)

Known Participant
May 31, 2020

Hi there, thanks for your response. I did notice the off/Off issue and changed it, but same result. It makes the field required (yipee) but keeps it required no matter which tick box I choose. In fact the "Off" makes no difference. Does the "!=" translate into "is not" in this case? Sorry I really have limited experience with this. I am sure I am missing something even more obvious than a capital O but I just can't work it out.