Expand my Community achievements bar.

string functions - comma-seperated string to list box items

Avatar

Former Community Member
Hi.



Wondering if anyone could help me with this - I am trying to split a comma seperated string into list box items.



I would prefer to use javascript but formcalc is fine too.
1 Reply

Avatar

Former Community Member
This works for a combobox / list box <br /><br />SAMPLE: http://www.sendspace.com/file/f1pf2w<br />(click the link & scroll down a little up to the dload link)<br /><br />Field containing a string consisting of items separated by commas,<br />Click on the button, which splits the string according to the specified delimiter, it sorts the items alphabetically, clears the current items in the listbox so that it does not append the new ones to the existing items & finally sets the items in the listbox<br /><br />var Items = field.rawValue.split(','); // splits using comma <br />Items.sort(); // sorts the items alphabetically<br />listbox.clearItems(); // clears the current items<br /><br />for(var i=0;i<Items.length;i++)<br /> <br />{<br /> listbox.addItem(Items[i]); // adds items <br />}