Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

jQuery: Post serialized form data with two extra fields

Using jQuery, I want to post all the data contained in #testform as well as two additional values.

This does NOT work:
$.post("test.php", xyz: "1", qrs: "2",  $("#testform").serialize());

Open in new window

Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Whats an example value of #testform
Avatar of leakim971
For example :
$.post("test.php", $("#testform").serialize() + "xyz=1&qrs=2" );

Open in new window

I miss an "&" :
$.post("test.php", $("#testform").serialize() + "&xyz=1&qrs=2" );

Open in new window

Test page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		alert( $("#testform").serialize() + "&outside1=" + $("[name='outside1']").val() + "&outside2=" + $("[name='outside2']").val()  );
	});
</script>
</head>
<body>
<form id="testform">
<input name="inside" value="in"/>
</form>
<input name="outside1" value="out1" />
<input name="outside2" value="out2" />
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the points!