Here is a crude snippet:
<html>
<head>
<title>Forms</title>
<script type="text/javascript">
function objectify() {
var o = {};
var frms = document.forms;
/* loop through all the form objects */
for(var i = 0, maxI = frms.length; i < maxI; ++i) {
var frm = frms[i];
var elms = frm.elements;
var tmp = {};
/* loop through all the form elements of each form */
for(var j = 0, maxJ = elms.length; j < maxJ; ++j) {
var el = elms[j];
switch(el.type) {
case "textarea":
case "text":
tmp[el.name] = el.value;
break;
default:
/* add custom behavior for other form elements */
break;
}
}
o[frm.name] = tmp;
}
return(o);
}
</script>
</head>
<body id="bdy">
<form name="frmOne" action="#">
<input name = "txtOne" value = "Text box one" />
<input name = "txtTwo" value = "Text box two" />
<input name = "txtThree" value = "Text box three" />
</form>
<form name="frmTwo" action="#">
<input name = "txtOne" value = "Text box one" />
<input name = "txtTwo" value = "Text box two" />
<input name = "txtThree" value = "Text box three" />
</form>
<form name="frmThree" action="#">
<input name = "txtOne" value = "Text box one" />
<input name = "txtTwo" value = "Text box two" />
<input name = "txtThree" value = "Text box three" />
</form>
</body>
</html>
Just pass the object returned by objectify function to a function which returns the json string representation of a javascript object.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."