Can I Put the "showRequired" Function into the First Half of my IF Statement?
Hi,
I have a Validate button on a form that has an IF statement that says, if the required fields have nothing in them, show a message that says to complete the required fields, and it also highlights them using the "showRequired" function.
If the required fields are already filled in, then it shows a message that says all required fields have been filled in.
The showRequired function is being called at the end of the IF statement, which makes the fields get highlighted whether they have all been filled in, or not.
I was just wondering if it is possible to put the showRequired function into the First Half of my IF statement, so that it would highlight them if they have NOT been filled in.
And, then, the code after the "ELSE" would just show the message that everything has been filled in, and it would not highlight the fields.
I have tried to do this, but I keep getting syntax errors and I have tried just about every way of re-doing it. Not having any luck.
I even tried turning the IF Statement around so that the first half is about if the fields have already been filled in, it gives that message, and then the 2nd half of the statement is when they have NOT been filled in, and so then the showRequired function could just come at the end.... But it can't be outside of the IF Statement, because then everything will highlight whether it's been filled in, Or Not.
Every time I try to include it in the IF statement, I get the syntax errors.
If you could please help me do the code, so that the function is only involved in one half of the IF statement, I would really appreciate it.
Here is my form in dropbox: Dropbox - generic form_2.pdf
Here is the code:
var oFieldNames = new Object();
function showRequired() {
for ( var i=0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if ( (f.type != "button") && f.required) {
oFieldNames[fname]={ strokeColor: f.strokeColor,
fillColor: f.fillColor};
f.strokeColor=color.red;
f.fillColor=app.runtimeHighlightColor;
}
}
}
if (
this.getField("EmpID1").value==""||
this.getField("EmpID2").value==""||
this.getField("EmpID3").value==""||
this.getField("EmpID4").value==""||
this.getField("EmpID5").value==""||
this.getField("EmpID6").value==""||
this.getField("EmpID7").value==""||
this.getField("EmpID8").value==""||
this.getField("EmpLName").value==""||
this.getField("EmpFName").value==""||
this.getField("EmpPhone").value==""||
this.getField("EmpEmail").value==""||
this.getField("ckYes").value=="Off"||
this.getField("EmpSignDate").value==""||
this.getField("EmpTitle").value==""||
this.getField("EmpDept").value==""
)
app.alert({
cMsg: "Please complete all required (*) fields",
nIcon: 1,
cTitle: "Validate Required Fields are Filled"
});
else
app.alert({
cMsg: "Thank you for completing all required (*) fields.",
nIcon: 3,
cTitle: "Validate Required Fields are Filled"
});
showRequired();
Thank you very much.
