jQuery Storage and retrieval form state (with data) -
is there way store form state in example cookie , retrieval ?
checked serialize api have no idea how retrieval serialized data on form.
possible?
update
i putted code here. check javascript code after // end of cookie plugin becasue sure jquery plugin works right.
yes, can serialize form values serialize(). syntax:
$("#your_form").serialize() will return string can handle, or save cookie (you can use jquery cookie plugin).
edit: above code serialize, hard retrieve.
should better use serializearray(), returns array of name value pairs ( like: [{name: "age", value: "23"}, {name: "sex", value: "male"}]). can see docs better explanation.
with that, can build "form string" function , "string form" function:
function form2string($form) { return json.stringify($form.serializearray()); } function string2form($form, serializedstr) { var fields = json.parse(serializedstr); for(var = 0; < fields.length; i++){ var controlname = fields[i].name; var controlvalue = fields[i].value; $form.find('[name=' + controlname + ']').val(controlvalue); } } use form2string serialize , string2form set string form. store , retrive serialization, can use cookie plugin.
hope helps. cheers
ps: json methods work in modern browsers
Comments
Post a Comment