I'm trying to build an array/object based on user-input to a form that has radios, checkboxs with radios, textfields with radios, and selects. I want the final array/object to be consolidated such that activated form-elements with repeated names are collapsed into a single object:
data = {
name0 = (value0,value4), // checkbox
name1 = (value2), // radio
name2 = (value5), // select>option
name4 = (''), // non-response
name5 = (NULL) // form element was disabled/hidden
}
Javascript seems to be rather picky, so I'm having some trouble. I've broken it up into 3 pieces (Arr1,Arr2,Arr3), but it seems like the first bit only retains the last form element and the second bit stops for each name after it's been encountered.
Code in JSfiddle: http://jsfiddle.net/jshado1/5Y7sn/12/
EDIT: What I want the final array to look like for the example in the fiddle is:
(with all alphas unchecked, beta=1 checked, beta=2 checked, and delta=3 selected)
data : {
{ 'alpha' : '' },
{ 'beta' : '1','2' },
{ 'delta' : '3' },
{ 'continue' : 'continue' }
}
(eventually I'll filter out [continue] using a more precise jQuery selector and put the button outside of a div)