count of comma seperated values

Swati30
Mega Expert

Kindly advice script for count the comma separated values and update in another variable.

 i have single line text contain values like 2009 , 2010, 2011 ...etc when they are entered these count has to update in another variable
ex: single line text variable1 : 2009 , 2010 , 2011

(single line text) variable4 has to update as 3

 

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Hi,

Please try this script.

var value = "2009 , 2010 , 2011";
var count = value.split(",").length;
alert(count);
g_form.setValue("variable4", count);

View solution in original post

2 REPLIES 2

Alikutty A
Tera Sage

Hi,

Please try this script.

var value = "2009 , 2010 , 2011";
var count = value.split(",").length;
alert(count);
g_form.setValue("variable4", count);

asifnoor
Kilo Patron

Hello Swati

do you need this on client side or server side?

In server side, here is how you can do it in BR.

var val = current.variables.var1.toString();

val = val.split(",");

current.variables.var4=val.length;

For client side, you can use the code provided by Ali.