We help IT Professionals succeed at work.

jQuery: Post serialized form data with two extra fields

hankknight
hankknight asked
on
935 Views
Last Modified: 2012-06-27
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

Comment
Watch Question

Greg AlexanderLead Developer

Commented:
Whats an example value of #testform
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
For example :
$.post("test.php", $("#testform").serialize() + "xyz=1&qrs=2" );

Open in new window

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

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

Open in new window

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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

Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Thanks for the points!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.