Coder Social home page Coder Social logo

dumorango / jquery.serializeobject Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hongymagic/jquery.serializeobject

0.0 1.0 0.0 83 KB

Encode a set of form elements as a JSON object for manipulation/submission.

Home Page: http://jsfiddle.net/davidhong/PRpJT/

jquery.serializeobject's Introduction

Build Status

What is it?

$.serializeObject is a variant of existing $.serialize method which, instead of encoding form elements to string, converts form elements to a valid JSON object which can be used in your JavaScript application.

Why?

Whilst it isn't necessary in most cases, and by that I mean 99.99% kind of most, there are times when we manipulate form data on client side. Personally I find JSON much easier to work with than DOM or string manipulation.

How do I use it?

If you want to see the code and demo first: http://jsfiddle.net/davidhong/PRpJT/

Simply include the jQuery.serializeObject.js along with any jQuery instance and use it like $.serialize.

If you have a form like the following:

<form id="minutes">
	<input type="text" name="subject">
	<input type="text" name="minute-taker">
	<!-- ... -->
	<input type="checkbox" name="attendees" value="David" checked="checked">
	<input type="checkbox" name="attendees" value="Daniel" checked="checked">
	<input type="checkbox" name="attendees" value="Darwin" checked="checked">
</form>

and wish to convert them to a JSON object:

var minutes = $('form#minutes').serializeObject();

will return:

{
	"subject": "",
	"minute-taker": "",
	"attendees": [
		"David",
		"Daniel",
		"Darwin"
	]
}

Change log

2.0.2

  • Add support for $.noConflict mode

2.0.0

Major version change: Camel casing of names have been removed. Please use version 1.0.4 if you require camel casing of names.

  • Remove $.data like camelCasing on names

1.0.4

  • Fix an issue (#2) where arrays longer than 2 resulted in incorrect values

jquery.serializeobject's People

Contributors

hongymagic avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.