Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

sets/gets form input values using JSON documents

branch: master

Merge pull request #1 from hooblei/master

Issue with initial field selector
latest commit 0687029794
Denny Shimkoski authored September 04, 2011
Octocat-spinner-32 README.markdown fixed link to qunit tests August 09, 2011
Octocat-spinner-32 jquery.inputs.js fixed input selector September 05, 2011
Octocat-spinner-32 tests.html fixed input selector September 05, 2011
README.markdown

jquery-inputs plugin

jquery-inputs is a jQuery plugin that allows set/get on form inputs using hierarchical JSON structures

Form Element Names

Supports various naming conventions, e.g., demo_field_key, demo.field[key], and demo[field].key will all be treated as synonymous references to the same value.

Empty brackets will automatically generate a 0-based index.

Usage

Include jQuery and the plugin:

<script src="jquery.inputs.js"></script>

Create a demo form:

<form id="demo-form">

    <input type="text" name="demo_text" value="textval" />

    <textarea name="demo_textarea">textareaval</textarea>

    <select name="demo_select" multiple="multiple">
        <option value="option_a" selected="selected">Option A</option>
        <option value="option_b" selected="selected">Option B</option>
    </select>

    <label><input type="radio" name="demo_radio" value="1" />1</label>
    <label><input type="radio" name="demo.radio" value="2" />2</label>

    <label><input type="checkbox" name="demo_checkbox" value="1" checked="checked" />1</label>
    <label><input type="checkbox" name="demo[checkbox]" value="2" checked="checked" />2</label>

</form>

Set/get values via javascript:

<script>
  jQuery(document).ready(function($) {

    $('#demo-form').inputs('set', {
        demo: {
            text: 'text',
            textarea: 'text',
            radio: 2,
            checkbox: 2, // [1,2]
            select: ['option_a', 'option_b']
        }
    });

    console.log( $('#demo-form').inputs('get') );

  });
</script>

See QUnit tests for further examples.

Author

Denny Shimkoski

Other

MIT License

Copyright (c) 2011, Denny Shimkoski (denny.webdev -[at]- gmail -[dot]- com)

Something went wrong with that request. Please try again.