Solved

jQuery: Exclude type of input from serialization

Posted on 2013-10-24
2
1,019 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
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

856 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