Serialize all fields
I've checked the jquery serialize docs and I'm trying to find the best way to serialize all fields in my form too much and then print the output, the demo has something like:
function showValues() {
var str = $("form").serialize();
$("#results").text(str);
}
$(":checkbox, :radio").click(showValues);
$("select").change(showValues);
showValues();
});
Even then, call the serialization on the form submit, use return false and show them.
Thoughts?
0
source to share
2 answers
Are you putting inside the document.ready method? It looks like you are ending this path ... It should be like:
$(function() {
$(":checkbox, :radio").click(showValues);
$("select").change(showValues);
$('form').bind('submit',function() { showValues(); return false; });
showValues();
});
function showValues() {
var str = $("form").serialize();
$("#results").text(str);
}
+1
source to share