Solved

jQuery: Exclude type of input from serialization

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JQuery Search Filter 2 67
ASP.NET MVC 5- How can I post textarea value using @Html.ActionLink? 8 53
Worldmap 1 28
How Close unsubmited attempts 10 42
by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
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 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…

735 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