akappycanfieldtack.com Posted June 20, 2011 Share Posted June 20, 2011 I have four fields and a graphic that depends on how many of the four fields have data (not empty). The following code always returns "EL_BC_1Lines.pdf" regardless. I don't seem to be adding the variables correctly. Perhaps there is a better way overall? I have a client pressing for a result! if(Field("Phone1")!="") var P1=1 if(Field("Phone2")!="") var P2=1 if(Field("Phone3")!="") var P3=1 if(Field("Phone4")!="") var P4=1 var PT=P1+P2+P3+P4 if (PT=1) return Resource("EL_BC_1Lines.pdf"); if (PT=2) return Resource("EL_BC_2Lines.pdf"); if (PT=3) return Resource("EL_BC_3Lines.pdf"); if (PT=4) return Resource("EL_BC_4Lines.pdf"); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted June 20, 2011 Share Posted June 20, 2011 I would do this: function CountNonEmptyFields() { var count = 0; for (var i = 0; i < arguments.length; i++) { if (Field(arguments[i])) count++; } return count; } var count = CountNonEmptyFields("Phone1", "Phone2", "Phone3", "Phone4"); return Resource("EL_BC_" + count + "Lines.pdf"); Quote Link to comment Share on other sites More sharing options...
akappycanfieldtack.com Posted June 20, 2011 Author Share Posted June 20, 2011 Dan, Thanks for the timely response, and as I hoped, the code is elegant. Much appreciated, Andy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.