I need to pass a few serialized form elements into a function to return them as a JSON object. I wrote the function, but fieldName ends up in the json object as "fieldName" instead of the actual field name ie; "PositionId", or "Series". The values however are correct. JS will not allow me to use field.name, but it does allow field.value, thats why I had to create var fieldName. Here is the function:
function SerializedFormToJSON(serializedForm){
var myJSONObject = {};
var fieldName = "";
$.each(serializedForm, function(i, field) {
fieldName = field.name;
if (field.value != "" && field.value != "ALL") {
myJSONObject = { fieldName: field.value };
}
});
return myJSONObject;
}