I have a form that has been generated by parsing a json object which is similar to
<h3>header<h3>
<label>dynamicName</label>
<input type ="text" name="dynamicName" value="dynamicValue"/>
<h3>header2<h3>
<label>dynamicName2</label>
<input type ="text" name="dynamicName2" value="dynamicValue2"/>
<label>dynamicName3</label>
<input type ="text" name="dynamicName3" value="dynamicValue3"/>
Now the form has to be converted back to json where header will be object and labels will be key value pair.... The problem I'm facing is I'm unable to group the fields during form creation as each field is checked for its type and based on that it's been append to a div.so while Converting back its plane key value pair.Tried many ways Bt nothing works. Any help would be greatly appreciated.. I tried
Obj=[] ;
$(#json).find('h3'). each(function)
{
var hd=$(#json).find('h3'). text() ;
$(#json).find('label').each(function)
{
var labelN=$(#json).find('label '). text();
var labelV=$(' # '+labelN). val();
Items={
Items[labelN] =[labelV] ;
}
Object . hd. push(Items);
And all the elements are being added to each header creating a mess.
The output I need is in format
Obj jsn={
"header1":
{
" dynamiclabel1":"dynamicValue1"
},
{
"header2":{
"dynamicName2":"dynamicValue2",
"dynamicName 3":"dynamicValue 3"
}
}........
The function used to create a dynamic form is
function addAttributeInput(obj) {
for (var o in obj) {
var vo=.val(obj[o]) ;
if (typeof obj[o] == "object") {
('#json'). append(<h3>o</h3>
addAttributeInput(obj[o]);
} else {
('#json'). append('<label >o</label>'<input type=" text" name='+o+' value ='+vo') ;
}
}
}
addAttributeInput(Obj) ;