Home & blog  /  2011  /  Aug  /  view post  /

Using Dropdown as a fancy form field

posted: 09 Aug '11 08:31 tags: dropdown, select, form

Not before time, I've updated my Dropdown plugin for jQuery. It now supports a new 'form field' mode, meaning you can use Dropdown as a fancy alternative to a <select> element, rather than just as a navigation tool.

As you'd expect of a real <select>, it submits a value to the server once the form is submitted.

It does this by creating a hidden field, whose value is updated every time an 'option' in the dropdown is selected. The name of this hidden field (i.e. the name of the value that should be sent to the server on submit) is denoted a parameter at set-up. Here's an example of using Dropdown in form field mode:

1new Dropdown({

2     mode: 'form',

3     data: [{val: 1, text: 'dog'}, {val: 2, text: 'cat'}, {val: 3, text: 'platipus'}],

4     startText: 'Select an option...',

5     fieldName: 'animal'

6});

Head over here to download, get usage info or view a demo.

post new comment

Comments (0)