• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

How do I make several radio buttons show a single text field?

Explorer ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

Good afternoon everyone.

At the start of every form we fill out, we usually have to write in our personal information such as name, address, phone number, etc.  I have something similar to that, but I want to give the user a chance to save what they have in a separate file before continuing.  In theory, what I'm doing is giving the user a chance to save the file to a new location so they don't accidentally overwrite their copy, and once they've entered all the pertinent information, a button will be revealed that when clicked executes a Menu Item of File>Save As .  Make sense?

Once the user fills all of these fields in, another text field labeled "Submit" will appear.  I'm using a text field because I'm using the Custom Calculation Script:

var bReady = true;

if(this.getField("DateOfReview").value.length == 0)   bReady = false;

else if(this.getField("ArrivalTime").value.length == 0)   bReady = false;

else if(this.getField("DepartureTime").value.length == 0)   bReady = false;

else if(this.getField("DateOfLastReview").value.length == 0)   bReady = false;

else if(this.getField("MonitorName").value.length == 0)   bReady = false;

else if(this.getField("MonitorTitle").value.length == 0)   bReady = false;

else if(this.getField("SiteName").value.length == 0)   bReady = false;

else if(this.getField("SiteID").value.length == 0)   bReady = false;

else if(this.getField("SiteAddress").value.length == 0)   bReady = false;

else if(this.getField("SiteRep").value.length == 0)   bReady = false;

else if(this.getField("SiteRepTitle").value.length == 0)   bReady = false;

if(bReady)   this.getField("Submit").display = display.visible;

else   this.getField("Submit").display = display.hidden;

The label "Submit" will later be changed; it was what I could think of at 2am...

I just don't know how to insert a radio group after Arrival Time and Departure Time.  Each field of "Time" has a radio button for "AM" or "PM".  We can't get rid of it; it's required to have separate radio buttons in this form, which is okay because then we can use the Arbitrary Mask 99:99 for each time field.

So how do I write in the line for the radio groups after each time?  It doesn't matter if AM or PM is selected, so long as one is.

I already know how to do a show/hide Action Script for revealing and hiding text boxes, but I can't seem to get that theory to apply with the rest of this. Is it possible?

Any help is appreciated.  Thanks!

TOPICS
Acrobat SDK and JavaScript

Views

262

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 12, 2018 Apr 12, 2018

I already answered the question. When no buttons in a radio button group are selected, the value of the group is "Off". So the if statement  needs to compare the value of radio button field to "Off".

A text field is a bad choice for a submit button. There is literally no reason why you can't use a button.

Likes

Translate

Translate
Community Expert ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

You really need to learn how to write more compact questions. There is way too much unrelated info here and it is difficult to parse. We don't have all day to answer questions for free.

So, I think the question you want answered is "How do you validate a Radio Button Group has a selected value". Even that was wordy.

The answer is simple, the value of an "unselected" radio button group is "Off".

On an unrelated note, is the calculation script you posted in the "Submit" field?  If so then the reference back to the Submit field is inefficient. Use "event.target".  There is also no reason to show the Submit Text field, why not use a Submit button. You're calculation script for validating the form can happily reside in a hidden text field, hiding or showing the submit button.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

I'm sorry. I figured to give as much detail for my question as possible so I don't lose people.  I don't often realize I still lose people by giving the detail.

The Submit button is actually a hidden text field.  The code I provided is in the Calculations.  When information is provided the subsequent fields, the Submit field button appears.

My question is: How do I also include radio button groups to the else if(this.getField code?  I've tried several different codes, and none of them can do what I want.  Is it even possible?  I feel as if there is a way, but nothing I've tried has worked.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

I already answered the question. When no buttons in a radio button group are selected, the value of the group is "Off". So the if statement  needs to compare the value of radio button field to "Off".

A text field is a bad choice for a submit button. There is literally no reason why you can't use a button.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

I'm clearly doing something wrong...

var bReady = true;

if(this.getField("DateOfReview").value.length == 0)   bReady = false;

else if(this.getField("ArrivalTime").value.length == 0)   bReady = false;

else if(this.getField("ArrivalTimeGroup").value.length == 0)   bReady = false;

else if(this.getField("Arrival1").value == Off) bReady = false;

else if(this.getField("Arrival2").value == Off) bReady = false;

if(bReady)   this.getField("SubB").display = display.visible;

else   this.getField("SubB").display = display.hidden;

I have to use a text field for the submit button because this goes into "Calculations".  Wasn't able to put it as a Javascript under the Actions for a real button.  But whatever works is all I care about right now.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

I'm sorry, but I'm very new to Javascript.  I'm able to understand it when I read it, but I can't write it without following steps and tutorials.  I've made it this far teaching myself through tutorials.

I do not know the event.target code you suggested using, and I can't seem to find anything remotely close to that.  All I can find is event.value.  I'm sorry if I gave off the impression that I can do this myself.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2018 Apr 12, 2018

Copy link to clipboard

Copied

LATEST

If your interested in learning JavaScript for Acrobat you'll find lots of tutorials, scripts, and such at http://www.pdfscripting.com

So first, the value of any field is a string. So the word "Off" has to be in quotes, since it's a literal string.

Next, there is no reason at all, none what-so-ever, that the calculation your using to validate the form and display the submit has to be in the same field that is used to submit. You can have this calculation in a text field and also use a button to perform the submit. This is the 3rd time I've written this. Go back and read my previous posts. If you want to learn you have to pay attention and read the advice you are given.

Have you seen the Acrobat JavaScript Reference? This is the golden source of information about Acrobat JavaScript. Here's the entry for the event object:

Acrobat DC SDK Documentation

It shows all the properties of the event object and explains what they are for. Read It!

If you would have simply typed "event.target" into the google search it would have returned plenty. If you would have used the Forum search you would have gotten tons of hits directly relevant to Acrobat JS. So I can't imagine what you did to not find anything.

The point of this forum is to help you write your own code. Not to provide free development. We don't get paid a thing to do this. So keep that in mind when you post questions. And if you are not willing or capable of writing the code yourself with a little help, then you should hire a developer.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines