Help with splitting an array only on first split

Baggies
Kilo Guru

I have a script that take a value from a text variable, and splits it into an array. It works fine..except, I want the firat array to go into the first text variable, and any subsequent arrays to go into a second text variable.

So, if I get the value from VarA, I want to split it, and push it to  VarB and VarC

If the user enters AAA BBB CCC DDD EEE in VarA 

VarB shows AAA

VarC shows BBB CCC DDD  because I don't have enough arrays defined.
------------------------------------------------------------------------------------------------

If the user enters AAA BBB  in VarA 

VarB shows AAA

VarC shows BBB undefined undefined  because I only have two arrays - anything extra is undefined

What I would like to see is:

VarA = AAA

VarB = anything that come after the first split, no matter how many subsequent splits there are.
------------------------------------------------------------------------------------------------

Many thanks for all replies.....Mark S.

Script is:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var full_name = g_form.getValue('VarA');
var array = full_name.split(" ");
var firstname1 = array[0];
var lastname2 = array[1];
var lastname3 = array[2];
var lastname4 = array[3];
g_form.setValue('VarB', array[0]);
g_form.setValue('VarC', lastname2 + " " + lastname3 + " " + lastname4);

}

 

1 ACCEPTED SOLUTION

This works just fine now. Many, many thanks!! This is the finished script:

find_real_file.png


function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var full_name = g_form.getValue('account_display_name');
var array = full_name.split(" ");
var firstname1 = array[0];

var x='';
for(var i=1;i<firstname1.length;i++)

{

x=x+' '+array[i];

}
g_form.setValue('u_first_name', array[0]);
g_form.setValue('u_last_name', full_name.split(array[0])[1].trim());
g_form.setReadOnly('u_first_name', true);
g_form.setReadOnly('u_last_name', true);

}

View solution in original post

11 REPLIES 11

Hi Ravinder, they all have a max of 63 chars. I tested also by removing this attribute. Cheers, Mark

max_length=63

Hi abhinay,

That is an awesome little piece of code! Should be really efficient to run too.

Brent

 

Thanks mate! Glad it helped you

Abhinay Erra
Giga Sage

Did you try the code I provided?

I am just about too...thanks...