Solved

jQuery: Exclude type of input from serialization

Posted on 2013-10-24
2
1,092 Views
Last Modified: 2013-10-24
Using jQuery, I want to get and serialize all values from a form except for the value of checkbox inputs.
<!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>
<title>Demo</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
 $('form').submit(function() {
   alert( 'I do not want "c=3" to be included because that input is a checkbox.\n\n' + $(this).serialize().replace(/\&/g,"\n") );
 });
});

</script>
</head>
<body>
 <form action="/" method="post"> 
  <input type="text" name="a" value="1" />
  <input type="text" name="b" value="2" />
  <input type="checkbox" name="c" value="3" checked="checked" />
  <input type="submit" value="submit"/>
 </form> 
</body>
</html>

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39599201
http://jsfiddle.net/wb8g2/1/

 $(":not(input[type=checkbox])",this).serialize().replace(/\&/g,"\n") );
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39599235
remove the name attribute :
<input type="checkbox" value="3" checked="checked" />
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question