PDA

View Full Version : split string and validate



jas8278
02-19-2016, 09:08 PM
I have a survey question that is a drag & drop that sorts from 1 list into 3 choice lists [Most important, Somewhat Important, Not Important]

The data is writing correctly. It starts out as: A,B,C,D,E,F,G,H,I,J

As you move the list items, it writes like this: C,E,I|F,H,A|J,D|G,B So it has pipe-separated the three destination lists.

When I did this before, I was only moving the options to one destination list and I was able to validate that using:

var str = document.forms[0].M9_p.value;
var res = str.split(",");
if(res.length<11) {
strErrorMessage="Please drag and drop all items";
}

Now my problem is that I donít know how to split the string and count only the remaining items to the left of the 1st pipe only.

Beverleyh
02-19-2016, 09:52 PM
Avoiding duplication - for reference - posted elsewhere http://www.webdeveloper.com/forum/showthread.php?353407-splitting-a-string-and-validating