HOWTO: Concatenate Fields

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

HOWTO: Concatenate Fields

Postby mattman » Tue Nov 04, 2003 8:15 pm

In JavaScript, the method for combining two fields together uses the plus sign "+" to act as the glue. Here is an example;

var my_variable = "Dear " + field.Salutation + " " + field.LastName

Result:

Dear Mr. Jones

----------------------
Developer Tip:

Notice that in JavaScript you can use either single quotes or double quotes. This allows for added functionality. Just make sure and match your opening quote with the same closing quote. For example;

var my_variable = 'Dear ' + field.Salutation + ' ' + field.LastName

Is the same as the above.

If you want to add a carriage return to your output then you need to use an escaped character. The letter "n" stands for "new line" and you would use "\n" to add the return. For example;

var my_variable = 'Dear ' + field.Salutation + ' ' + field.LastName + '\nof ' + field.Address

Result:

Dear Mr. Jones
of 555 Waverly Rd.
Matt Petrowsky
mattman
 
Posts: 160
Joined: Wed Aug 06, 2003 8:23 am
Location: Murrieta, CA

Return to How To

Who is online

Users browsing this forum: No registered users and 3 guests