I have a simple HTML form:
<form id="formid1" action="#" method="post">
<table>
<tr><td> First name: </td><td><input type="text" name="firstname" id="firstname"/> </td></tr>
<tr><td> Last name: </td><td><input type="text" name="lastname" id="lastname"/> </td></tr>
<tr><td> Address: </td><td> <input type="text" name="address" id="address"/> </td></tr>
<tr><td> Zip: </td><td> <input type="text" name="zip" id="zip"/> </td></tr>
<tr><td> Sex: </td><td> <input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female<br /></td></tr>
<tr><td> </td><td> <input type="submit" value="Submit" /></td></tr>
</table>
</form>
I need to get a JSON representation of the Form elements including id, value, type, form action, form id etc.
I tried playing with the following code but I am not getting what I am looking for:
<script>
$(document).ready(function(){
var encoded = $.toJSON($('#formid1'));
$("#formid1").submit(function() {
$.colorbox({html:'<p>Form Converted to JSON Data: <br /><br /><br /><br /><br /></p>'+ encoded });
return false;
});
});
</script>
I get:
{"length":1,"0":{"firstname":{},"lastname":{},"address":{},"zip":{},"sex":{"0":{},"1":{}},"6":{}},"context":{"jQuery16108216209608688556":1},"selector":"#formid1"}
close