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

Javascript Radio Button app.alert

Guest
Aug 22, 2016 Aug 22, 2016

I have a pdf form that has required text fields and radio buttons. Once the user has filled out the form I've created a button that will check to see if all the required fields have been filled out, if yes then send an email, and then close the form without saving. If no, an app alert pops up and allows you to fill in the missing information. The app.alert works for the text fields but not the radio buttons. If the radio button is the only thing not filled out, I get the default error and then it skips the email portion and closes without saving the pdf. I have one set of radio buttons (qty of 3) called "group". Here is the JavaScript. Can someone please help.

var requiredFields = new Array();

for (var i = 0; i < this.numFields; i++)

{

var fName = this.getNthFieldName(i);

var f = this.getField(fName);

if (f.type!="button" && this.getField(fName).required && (this.getField(fName).value == null || this.getField(fName).value == ''))

{

requiredFields[requiredFields.length] = fName;}}

var error = "Please complete the following fields: \n\n";

for (j=0; j < requiredFields.length; j++)

{

if (requiredFields.value == null)

{

error = error + requiredFields + '\n';

var f2 = this.getField(requiredFields);

f2.setFocus();

}

 

}

 

if (requiredFields.length > 0) {

app.alert(error);

} else {

this.submitForm ({

cURL:"mailto:none@none.com",

cSubmitAs: "PDF",

})

this.closeDoc(true);

}

TOPICS
Acrobat SDK and JavaScript , Windows
1.7K
Translate
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 , Aug 22, 2016 Aug 22, 2016

The default value of a radio-button group when no button is selected is "Off", not null.

Translate
Community Expert ,
Aug 22, 2016 Aug 22, 2016

The default value of a radio-button group when no button is selected is "Off", not null.

Translate
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
Guest
Aug 23, 2016 Aug 23, 2016

I changed both nulls to off and it doesn't work as well as changing each one separately and it didn't work. I guess I don't understand what I'm suppose to change.

Translate
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 ,
Aug 23, 2016 Aug 23, 2016

It's not "off" but "Off". JS is case-sensitive.

Translate
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
Guest
Aug 23, 2016 Aug 23, 2016

Sorry, I changed them to "Off" and it didn't work. It says Off is not defined.

Translate
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 ,
Aug 23, 2016 Aug 23, 2016

Did you include the double-quotes around it?

Translate
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
Guest
Aug 23, 2016 Aug 23, 2016

Maybe not Now it works. Thanks for your help!

Translate
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
Guest
Aug 23, 2016 Aug 23, 2016

Here is the updated code:

var requiredFields = new Array();

for (var i = 0; i < this.numFields; i++)

{

var fName = this.getNthFieldName(i);

var f = this.getField(fName);

if (f.type!="button" && this.getField(fName).required && (this.getField(fName).value == "Off" || this.getField(fName).value == ''))

{

requiredFields[requiredFields.length] = fName;}}

var error = "Please complete the following fields: \n\n";

for (j=0; j < requiredFields.length; j++)

{

if (requiredFields.value == null)

{

error = error + requiredFields + '\n';

var f2 = this.getField(requiredFields);

f2.setFocus();

}

 

}

 

if (requiredFields.length > 0) {

app.alert(error);

} else {

this.submitForm ({

cURL:"mailto:none@none.com",

cSubmitAs: "PDF",

})

this.closeDoc(true);

}

Notice the "Off" is just in the first if statement. null is needed in the second if statement for the error message to display the required fields that are still blank.

Translate
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
LEGEND ,
Aug 23, 2016 Aug 23, 2016
LATEST

A field value will never be equal to null, so it's misleading to compare a field value with it.

If a user enters the string "Off" in a required text field, it will be considered incomplete by that code.

If you have any dropdowns, list fields, or radio buttons, you'll probably want to check their values against their default values to see if a valid selection has been made.

Translate
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