Solved

jQuery: Exclude type of input from serialization

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
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…

777 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