Post

2 followers Follow
0
Avatar

Javascript help

I need help with some javascript

 

This is what I currently have

@Qty, +@Manufacturer, +@Model, +@Serial Number +@Problem or Service Requested +@Cost

 

I need two things

1. commas in between each field

2. If the field is empty just have nothing (not even commas), not NULL

Tanya Peila

Please sign in to leave a comment.

1 comment

1
Avatar

Hi Tanya,

to get the commas you must wrap them in quotation marks (double or single, doesn't matter).

@Qty + "," +@Manufacturer + "," + @Model + "," +@Serial Number + "," +@Problem or Service Requested + "," +@Cost

To avoid superfluous commas and nulls if the field is empty:

var arr = [@Qty,@Manufacturer,@Model,@Serial Number,@Problem or Service Requested,@Cost];
arr.filter(function(i){return i != null;}).join()

If you want comma plus blank space:

arr.join(", ")

Rainer

Rainer Grabowski 1 vote
Comment actions Permalink