last day (27 days later) » 

7:42 AM
0
A: Javascript Muilti Sub Array

Parv Sharmatry this code i have just edited it a little function createSubArray(name){ var arr = []; elems = document.getElementsByName(name); for (var i=0;i<elems.length;i++){ if (elems[i].checked){ var o = {} o[name] = elems[i].value; o['price'...

 
Not Working Sir
 
ok i think the top level object should have been an array too.. i have edited my ans and the response string that i was getting have a look
 
not its not the correct answer check here i need like this jsfiddle.net/yJkEE
 
the json you have provided isnt valid. try jsonlint.com
 
kindly check the question where 'But i need to array to be like below' is written
 
7:42 AM
yeah i have seen that.. i think that is also not correct. can you please add a valid JSON string to teh question like the one you want?
 
the above is not an json its an array
 
hi
 
tell me the exact JSON structure you want
 
yes one min i will give u
i need it like this
{ "apple":[{"productname": "light", "price": "12", "qty": "1"},{"productname": "light1", "price": "12", "qty": "1"}], "Mango":[{"productname": "light", "price": "12", "qty": "1"}] }
and the above json should be pushed to another json
 
7:48 AM
something like this
{"apple":[{"apple":"light","price":"10"},{"apple":"dark","price":"20"}],"mango":[‌​{"Mango":"light","price":"30"},{"Mango":"dark","price":"40"}],"Pineapple":[{"Pine‌​apple":"light","price":"50"},{"Pineapple":"dark","price":"60"}],"grape":[{"Grape"‌​:"light","price":"70"},{"Grape":"dark","price":"80"}]}
 
like this
{
"Products":
{
"apple":["apple12":{"apple":"light","price":"10"},"apple14":{"apple":"dark","price":"20"}],
"mango":[‌​{"Mango":"light","price":"30"},{"Mango":"dark","price":"40"}],
"Pineapple":[{"Pine‌​apple":"light","price":"50"},{"Pineapple":"dark","price":"60"}],
"grape":[{"Grape"‌​:"light","price":"70"},{"Grape":"dark","price":"80"}]
}
}
 
this is invalid
 
one min
 
you cannot have a structure like this
["some name":"some value"]
[] stands for array
 
can i tell u what i need exactly in word no t in json
i have a html form like this
 
7:53 AM
sure
 
<form method="post">
Apple
<input type="radio" onclick="createArray()" id="one" name="apple" data-gpname="apple" data-subname="Lil" data-price="10" value="light"/> Light
<input type="radio" onclick="createArray()" id="two" name="apple" data-gpname="apple" data-subname="Lil"data-price="20" value="dark" /> Dark
<input type="radio" onclick="createArray()" id="one1" name="apple1" data-gpname="apple" data-subname="Li1" data-price="120" value="light2"/> Light11
<input type="radio" onclick="createArray()" id="two1" name="apple1" data-gpname="apple" data-subname="Lil1"data-price="210" value="dark1"
the data-subname in the form change for every 2 radio buttons
right
?
 
i need to group by like
productname => subcatname => and the selected val
like
{"products" : {"apple" : {"Lil" : {"productname":"light","productprice":"10"}."Li1" : {"productname":"light","productprice":"10"} } } }
like this
{
"products": {
"apple": {
"Lil": {
"productname": "light",
"productprice": "10"
},
"Li1": {
"productname": "light",
"productprice": "10"
}
}
}
}
apple in the json will be given by data-gpname variable in the radio button
Lil in the json will be give by data-subname variable in the radio button
 
k gt this.. i have to leave nw.. giv me some time.. sm1 will ans the ques or i will..
 
ok
 
 
3 hours later…
10:37 AM
@ParvSharma ok no problem
 

  last day (27 days later) »