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

Currently cannot figure out how to add radio buttons to this javascript so it works on them aswell.

New Here ,
Sep 16, 2016 Sep 16, 2016

I am trying to add radio buttons to the if statement so that they get highlighted when not clicked on aswell

Thanks Much

var emptyFields = [];

var completedFields = [];

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

     var f= this.getField(this.getNthFieldName(i));

     var v= this.getField(this.getNthFieldName(i));      

          

if (f.type!="button" && f.required ) {

        f.strokeColor = color.black;

        f.fillColor = color.white;

          if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off") || (v.value==" ")) {

            emptyFields.push(f.name);

            f.strokeColor = color.red;

            f.fillColor = color.white;

  }                

        

}

}

if (emptyFields.length>0) {

app.alert("Error! You must fill in all required fields (Highlighted in red)");

}

TOPICS
Acrobat SDK and JavaScript , Windows
440
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

LEGEND , Sep 20, 2016 Sep 20, 2016

Try the following. I removed some extraneous stuff and formatted it for readability.

var emptyFields = [];

for (var i = 0; i < numFields; i++) {

    var f = getField(getNthFieldName(i));

         

    if (f.type != "button" && f.required ) {

        f.strokeColor = color.black;

   

        if (

            (f.type == "text" && f.valueAsString == "")

         || (f.type == "checkbox" && f.valueAsString == "Off")

         || (f.type == "radiobutton" && f.valueAsString == "Off")

         || (f.type == "combo

...
Translate
New Here ,
Sep 20, 2016 Sep 20, 2016

I am still struggling with this any help would be greatly appreciated

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
New Here ,
Sep 20, 2016 Sep 20, 2016

I tried f.type=="radio" && f.value=="Off" as another or statement but this doesnt work

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 ,
Sep 20, 2016 Sep 20, 2016

Try the following. I removed some extraneous stuff and formatted it for readability.

var emptyFields = [];

for (var i = 0; i < numFields; i++) {

    var f = getField(getNthFieldName(i));

         

    if (f.type != "button" && f.required ) {

        f.strokeColor = color.black;

   

        if (

            (f.type == "text" && f.valueAsString == "")

         || (f.type == "checkbox" && f.valueAsString == "Off")

         || (f.type == "radiobutton" && f.valueAsString == "Off")

         || (f.type == "combobox" && f.valueAsString == " ")) {

  

            emptyFields.push(f.name);

            f.strokeColor = color.red;

        }

    }               

   

}

if (emptyFields.length > 0) {

    app.alert("Error! You must fill in all required fields (Highlighted in red)");

}

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
New Here ,
Sep 20, 2016 Sep 20, 2016
LATEST

Thanks a ton i knew all i was doing was using the wrong naming conventions. although yours is much prettier and probably much more effecient. Worked like a charm!

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