I have 2 divs where 1st div has 2 text boxes while the other div has several text boxes
Manually I am adding the textbox name and value to an object for the 1st div. But for second div I am getting all the textbox names and values using jQuery to avoid having a large block of similar code.
var obj = {};
obj.LayoutName = document.getElementById("aSL_stripLayoutName").value;
obj.Version = document.getElementById("aSL_StripLayoutVersion").value;
Then I want to extend the object and add all textbox names and values to 'obj' using extend,
$("#aSL_stripLayoutDetails-UpperSection :text").each(function(){
What I have tried:
I have tried the below and an example is working adding a known textbox name 'StripDimX' and value '333'
$.extend(obj, {StripDimX : "333"});
If I want to get the name I use this inside the below function
document.getElementById(this.id).name
and this for the value
document.getElementById(this.id).value
But my problem is how to add the names and values to the object?
$("#aSL_stripLayoutDetails-UpperSection :text").each(function(){
});
This of course does not work:
$("#aSL_stripLayoutDetails-UpperSection :text").each(function(){
$.extend(obj, {document.getElementById(this.id).name: document.getElementById(this.id).value});
});
Then I tried the below and name is ok, but the value is being added as an array:
$("#aSL_stripLayoutDetails-UpperSection :text").each(function(){
var n = document.getElementById(this.id).name;
var v = document.getElementById(this.id).value;
$.extend(obj, { [n] : [v]});
});