Skip to main content
JensCom
Participant
September 16, 2016
Answered

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

  • September 16, 2016
  • 3 replies
  • 499 views

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)");

}

This topic has been closed for replies.
Correct answer George_Johnson

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)");

}

3 replies

JensCom
JensComAuthor
Participant
September 20, 2016

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!

George_JohnsonCorrect answer
Inspiring
September 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)");

}

JensCom
JensComAuthor
Participant
September 20, 2016

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

JensCom
JensComAuthor
Participant
September 20, 2016

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