0

I'm currently looping around a series of checkboxes that have a specific name assigned to them. Whatever checkbox is checked it gets the value and puts it in an array.

var filterHeight = $('input[name="filter-height"]:checked');
var userArray = []; 
filterHeight.each(function(){
 userArray.push($(this).val()); 
});

So the output could be something like short, medium, tall

How would I assign a key value to the array values? I'm looking to do something like:

$(document).trigger('showHeight', {
 short: true,
 medium: false,
 tall: false
 }
});

Any help is appreciated!

asked Oct 14, 2013 at 23:34
1
  • userArray[$(this).val()] = true; Commented Oct 14, 2013 at 23:38

1 Answer 1

2

You need an object so try:

var filterHeight = $('input[name="filter-height"]');
var userObj = {}; 
filterHeight.each(function () {
 userObj[this.value] = this.checked;
});
$(document).trigger('showHeight', userObj);

Demo

answered Oct 14, 2013 at 23:38
Sign up to request clarification or add additional context in comments.

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.