Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
jQuery plugin to GET or SET form fields to/from JS object
JavaScript CSS
branch: master
Failed to load latest commit information.
dist grunt; tests;
lib grunt; tests;
src default to null
test code coverage
.gitignore package & bower
Gruntfile.js lintest
README.md .
bower.json default to null
index.html grunt; tests;
package.json default to null

README.md

FormParams

NPM version Build Status devDependency Status Built with Grunt

jQuery plugin to GET or SET form fields to/from JS object.

Installation

bower install form-params

Basic usage

<form id="testForm">
    <input name="name" placeholder="name" value="tom"/>
    <input name="surname" placeholder="surname" value="B"/>
    <input type="checkbox" name="optin" />Opt-In<br>
    <input type="radio" name="gender" value="m" />M <input type="radio" name="gender" value="f" />F<br>
    <input name="address[line1]" placeholder="address line 1" value=""/>
    <input name="address[line2]" placeholder="address line 2" value=""/>
    <input name="address[line3]" placeholder="address line 3" value=""/>
</form>
$(function(){
    // GET form fields to object
    var formObj = $('#testForm').formParams();

    // GET form fields to object and convert types ('123' to 123, 'true' to true)
    var formObj = $('#testForm').formParams(true);


    // SET form fields from object
    // (form fields that do not have the corresponding value in the object are left unchanged):
    $('#testForm').formParams(formObj);

    // SET form fields from object
    // and clear form fields that don't have the corresponding value in the object
    $('#testForm').formParams(formObj, true);
});

Demo included (just open index.html)

Something went wrong with that request. Please try again.