Jump to content

Function not working

Recommended Posts

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+", "+cred+": ";

   if (email=""){
   }else if(phone=""){
       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:




Why doesn't it work?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...