Hi everyone,
I am currently working on a project where data is being passed from the cilent side to the server side quite a lot. I thought that AJAX and JSON would be perfect for this. I have written a small function to generate what I thought was JSON data:
[code=javascript]
function generateJSON(pc IDList)
{
// set the default return
lcReturn = "" ;
lcJSONString = '{';
if (pcObjectName != "" && pcIDList != "")
{
// take the data into a JSON structure
laIDList = pcIDList.split( ",");
for(lnPntr in laIDList)
{
lcElementID = laIDList[lnPntr] ;
lcElement = document.getEle mentById(lcElem entID) ;
lcJSONString += lcElement.name + ':' + lcElement.value ;
if(lnPntr < (laIDList.lengt h - 1))
{
lcJSONString += ',' ;
}
}
lcJSONString += '}' ;
lcReturn = lcJSONString ;
}
return lcReturn ;
}
[/code]
The parameter pcIDList is a comma separated list of from control ID's. So if I pass in:
from a form where I have asked for 5 sets of data all in group 6 the output is:
I'm not sure this is correct, but all my reading around on the subject has left me rather confused, so I'm seeking help. The final part of my current problem is how then to pass this data set from my JavaScript to my PHP so that it can be parsed correctly and used to control the process flow and eventually update the database.
Many thanks
nathj
I am currently working on a project where data is being passed from the cilent side to the server side quite a lot. I thought that AJAX and JSON would be perfect for this. I have written a small function to generate what I thought was JSON data:
[code=javascript]
function generateJSON(pc IDList)
{
// set the default return
lcReturn = "" ;
lcJSONString = '{';
if (pcObjectName != "" && pcIDList != "")
{
// take the data into a JSON structure
laIDList = pcIDList.split( ",");
for(lnPntr in laIDList)
{
lcElementID = laIDList[lnPntr] ;
lcElement = document.getEle mentById(lcElem entID) ;
lcJSONString += lcElement.name + ':' + lcElement.value ;
if(lnPntr < (laIDList.lengt h - 1))
{
lcJSONString += ',' ;
}
}
lcJSONString += '}' ;
lcReturn = lcJSONString ;
}
return lcReturn ;
}
[/code]
The parameter pcIDList is a comma separated list of from control ID's. So if I pass in:
Code:
'dataQuantity,sameGroup,groupNumber'
Code:
{dataQuantity:1,sameGroup:false,groupSelect:2}
Many thanks
nathj
Comment