I have an array of input fields’ ids. The problem is that they are either text field or select box. For select box, I want the inner text and for the input field I would like to get the value and put it in an object. It’s identical to serializeObject() if not for the treatment of select box. I wonder if the following snippet is best way to achieve this goal:
var ids = [/* a bunch of ids here */]
var inputs = {}
$.each(ids, function(k,v){
// is there any jQuery ready-made way to do this?
var input = $('#' + v + ' :selected').text();
inputs[v] = (input === '') ? $('#' + v).val() : input;
});
That should do it. o/