We help IT Professionals succeed at work.
Get Started

How do I serialize data in a button's surrounding form?

SiobhanElara asked
Last Modified: 2020-02-26
I have a simple form:
<div id="notify-alert"></div>
<form method="post">
<input type="hidden" name="memberID" value="5">
<input type="hidden" name="requestID" value="23">
<input type="button" name="submitNotify" value="Notify" onclick="SubmitNotification();">

Open in new window

the SubmitNotification function is as follows:
function SubmitNotification(){
	//these next four lines were to check what was going on
	var thisData = $(this).closest('form').serialize(); 
		type: "POST",
		url: "ajax-notify.cfm",
		data: $(this).closest('form').serialize(),
		dataType: "text",
		success: function(data, status) {
		error: function(data, status) {

Open in new window

$(this).closest('form').serialize(); is just returning an empty string. I've found several questions about how to serialize the surrounding form of a button and this appears to be to the correct way... where is this going awry? (I've also tried $(this).parent('form') with the same issue. Incidentally, I'm not using an ID for this because there are multiple forms on the page created by a loop.) Thanks!
Watch Question
Prepress/OMS Specialist
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE