mark007
11-25-2008, 01:51 PM
Hi all,
I have a form with multiple fields (around 50) which I need to store to sql database. I have some nice php code that can take my json id value pairs and add it to the correct fields in the mysql database.
All I need to give it is valid json and it does the rest. My problem is creating json for this large collection of fields without doing it manually.
So my json object needs to be made from dom id, value pairs from nodes with classname input.
# I can get this list of input fields like this
var list=dojo.query(".input");
# I can then get their ids and values in a loop like this
for (var i=0;i<list.length;i++)
{
var id=list[i].id;
var value=list[i].value;
}
How can I create an object of the following structure, using the loop above or is it possible?
var data={
orderer_id: dojo.byId("orderer_id").value,
final_comments_id: dojo.byId("final_comments_id").value
...,
...
};
If I can create this data object on the fly without manually specifying any fields in it, I can then use the method below to convert it to perfect json.
var json_of_data=dojo.toJson(data);
Thanks for any suggestions,
Mark
I have a form with multiple fields (around 50) which I need to store to sql database. I have some nice php code that can take my json id value pairs and add it to the correct fields in the mysql database.
All I need to give it is valid json and it does the rest. My problem is creating json for this large collection of fields without doing it manually.
So my json object needs to be made from dom id, value pairs from nodes with classname input.
# I can get this list of input fields like this
var list=dojo.query(".input");
# I can then get their ids and values in a loop like this
for (var i=0;i<list.length;i++)
{
var id=list[i].id;
var value=list[i].value;
}
How can I create an object of the following structure, using the loop above or is it possible?
var data={
orderer_id: dojo.byId("orderer_id").value,
final_comments_id: dojo.byId("final_comments_id").value
...,
...
};
If I can create this data object on the fly without manually specifying any fields in it, I can then use the method below to convert it to perfect json.
var json_of_data=dojo.toJson(data);
Thanks for any suggestions,
Mark