1
 var coptions = $(me).parents('tr').find('td.desCell > .coptions').val();
 var chosenOptions = [coptions];

Is what I have tried to do.

coptions contains:
'Black', 'White'

I need to wrap it in [], and make the javascript read it as an array, but doing [coptions] wont work?

Also tried '[' + coptions + ']' , but then it reads this as a string.

How can I do this? If not, any workaround/solution to make it work? Maybe mulitple .coptions inputs (hidden inputs) with each "Black" and another "White" and then loop through with js to add to an array? How would this be done?

asked Sep 15, 2012 at 13:06
0

3 Answers 3

2

You can use map method.

var coptions = $(me).parents('tr').find('td.desCell > .coptions').map(function(){
 return this.value
 }).get()
answered Sep 15, 2012 at 13:08
Sign up to request clarification or add additional context in comments.

1 Comment

@Karem No coptions should be an array of values. if your selector is correct.
1

Try this, assuming your selector is correct.

var chosenOptions = [];
$(this).parents('tr').find('td.desCell > .coptions').each(function(){
 chosenOptions.push($(this).val());
});
answered Sep 15, 2012 at 13:09

Comments

0

This would return an array:

coptions = coptions.split(",");
answered Sep 15, 2012 at 13:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.