/    Sign up×
Community /Pin to ProfileBookmark

Formating a form variable containing multiple values

My situation is that I have a <select> list within a form where multiple values may be selected and I would like to alter the way it’s values are formatted. Is there a dynamic or universal function that could be used so that the output changes from:

1,2,3,4

to:

1,2,3 and 4

Also, in the event that only one option is selected the verbiage “and ” wouldn’t be inserted just before the last value. Basically, if there is more than one value, “and ” is inserted just before the last value in the list.

Thank you so much to anyone who may be able to help me with this!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @gregw74 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...