Solved

jQuery: Exclude type of input from serialization

Posted on 2013-10-24
2
953 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now