seymoujd Posted June 16, 2015 Share Posted June 16, 2015 Here is how i want my returned text to look: Joshua Seymour, PH.D: 918.345.4567, seymoujd@nsuok.com I have two contact lines so i created a function globals. It looks like this: function contactInfo(nAme,cred,phone,email) { var namCred=""; var info=""; if (cred=""){ namCred=nAme; }else{ namCred=nAme+", "+cred+": "; }; if (email=""){ info=phone; }else if(phone=""){ info=email; }else{ info=phone+", "+email; }; var contact=namCred+info; return contact; }; my rule looks like this: return contactInfo(Field("Name 1"),Field("Credentials 1"),Rule("Rule Phone 1 Format"),Field("Email 1")); None of the fields are blank but the function returns this: Josh,:, Why doesn't it work? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted June 16, 2015 Share Posted June 16, 2015 The equality operator in JavaScript is two equal signs. One equal sign is the assignment operator. So this line: if (cred=""){ Should be: if (cred==""){ Or simply: if (!cred){ And likewise for the other "if" conditions. Of course, this logic can be reduced in several ways. Here's how I would write the function: function contactInfo(name,cred,phone,email) { return [ [name,cred].filter(String).join(", "), [phone,email].filter(String).join(", ") ].join(": "); } Quote Link to comment Share on other sites More sharing options...
seymoujd Posted June 17, 2015 Author Share Posted June 17, 2015 Great. Thank you for your help. 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.