1

I saved ONE or MORE THAN ONE values from multiply select option to one value in DB. for example:" Name1, Name2, Name3 "

When I leave from page and then return to page I need load and preselected these values to multiply select option.

I need this :

$("#form_meno").val([**"Name1", "Name2", "Name3"**]);

But I dont know how I convert it.

2
  • Please share the code which you have tried. Commented Apr 15, 2019 at 13:51
  • long story made short. do not store multiple values in the same table cell... that's the reason why you won't find a function to cover your need. Commented Apr 15, 2019 at 13:51

1 Answer 1

1

You can use split() after removing the whitespaces using replace()

let str = " Name1, Name2, Name3 ";
let arr = str.replace(/\s+/g,'').split(',');
console.log(arr)

Sign up to request clarification or add additional context in comments.

1 Comment

Depend on how you save these values but you can use str.trim().split(', ') as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.