jquery - Adding a list of data to object inisde loop -


i have been attempting add list of values object/associative array can list of values input of multiselect plugin. im wanting add name of input object key.

problem: doesnt seem create list, updates last input value in loop...what doing wrong here?

var selectobj = {};   $('input').each(function(inputkey) {     alert($(this).val());   //all input values shown     selectobj[$(this).attr('name')] = $(this).val();   });  alert(json.stringify(selectobj));    //last input value shown 

desired results:

  • (1 multi-select):

selectobj={"listname1":"12,3,31,4"}

  • (2 multi-select):

selectobj={"listname1":"12,3,31,4"},{"listname2":"1,32,43,5"}

this can based on edits of desired results

var selectobj = {};  var inputvalues = []; $('input').each(function(inputkey){   attrname = $(this).attr('name');   inputvalues.push(value);  });  selectobj[attrname] = inputvalues .tostring(); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -