$("#fieldset").closest("fieldset").find("input, select,textarea").change(function() {
return ($(this).val());
}).get().join(',');
I am getting all editable field values on change.. I need to store all editable values in an array to pass to the controller?
how to store the values in an array
thanks
The
#fieldsetchange event will fire when any of its descendant elements are changed.Then handler finds the input/select/textarea elements, and performs
.map()on them returning their value, which creates a jQuery object with the values..get()grabs/returns the array from the jQuery object.Test it here: http://jsfiddle.net/Mrrty/2/ (change the value of one of the elements)
EDIT:
Note that if you don’t want to get a new array every time one of the elements changes, you can do the same thing with a different event. Perhaps doing this on
.submit()would be more appropriate.