jQuery Serialize Function

Posted on: December 12th, 2011 by richardreay

I discovered this super useful jQuery function recently when I was working on a project, you run this on a form and it converts the form elements into a query string representing the state of the various elements, a simple method for creating a query string to be used with AJAX updates:

$(function() {
	var loadUrl = "page.php";
	function showValues() {
		var str = $("form").serialize();
		$("#updatethiselement").load(loadUrl, str);
	}
	$("input[name='color']:radio").change(showValues);
});

More Info: http://api.jquery.com/serialize/

Leave a Reply


© Richard Reay, A Whitley Bay Web Designer