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
Karem
18.2k73 gold badges183 silver badges282 bronze badges
3 Answers 3
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
Ram
145k16 gold badges174 silver badges201 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Ram
@Karem No
coptions should be an array of values. if your selector is correct.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
Adil
148k25 gold badges217 silver badges207 bronze badges
Comments
This would return an array:
coptions = coptions.split(",");
answered Sep 15, 2012 at 13:10
Stuiterbal
4574 silver badges11 bronze badges
Comments
lang-js