/    Sign up×
Community /Pin to ProfileBookmark

splitting a string and validating

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.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@benmartin101Feb 19.2016 — Split the pipe delimited maybe? ie. split("|")

to be honest, I'm still not sure what you are saying. Perhaps you can explain it more?
Copy linkTweet thisAlerts:
@jas8278authorFeb 19.2016 — Sorry this wasn't clear.

In this example: C,E,I|F,H,A|J,D|G,B items C,E,I haven't been moved into one of the 3 choice lists

So yes, I need to split("|") and then count how many items are to the left . . . but only on the first "|"

A correct final data string would look like: |F,H,C,A|J,D,E|I,G,B

Thank you!
Copy linkTweet thisAlerts:
@rootFeb 20.2016 — You split and create an array so the first reference indices will be zero.
str[0] will contain the first set.
Copy linkTweet thisAlerts:
@jas8278authorFeb 20.2016 — Thank you! It's working.
×

Success!

Help @jas8278 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...