Coder Social home page Coder Social logo

marcuschristiansen / jquery.popselectoptions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gar-cad/jquery.popselectoptions

0.0 1.0 0.0 3 KB

A simple jquery plugin to populate a select element(s) with options from an array.

License: MIT License

jquery.popselectoptions's Introduction

jquery.popSelectOptions

A simple jquery plugin to populate a select element(s) with options from an array. It takes 2 parameters:

  1. options: An array of dictionaries, storing the value of each option tag, and the label to display. Default: [{'value': '-', 'label': 'Default option'}]
  2. default: The position in the options array to use as the default item. Default: 0

Prerequisites

jquery 2.0.1

Set up

Install the plugin, and use the following source code as an example. Basic use (using the default syntax), more examples can be found in the demo folder.

HTML
<div class="form-row my-2">
    <div class="form-group col-md-4">
        <label for="distance">Distance</label>
    </div>
    <div class="form-group col-md-8">
        <select id="distance" class="form-control"></select>
    </div>
</div>
javascript
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="../dist/jquery.popSelectOptions.min.js"></script>
<script>
    var distances = [
        {'value': '1609.34', 'label': 'Mile(s)'},
        {'value': '1000', 'label': 'Kilometre(s)'},
        {'value': '1', 'label': 'Metre(s)'},
        {'value': '0.9144', 'label': 'Yard(s)'},
        {'value': '0.3048', 'label': 'Feet'}
    ];
    $(function() {
        $('#distance').popSelectOptions({'options': distances, 'default':2});
    })
</script>

Examples

View the examples in the demo folder.

Author

  • Gareth Cadwaladr - Initial work - gar-cad

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

jquery.popselectoptions's People

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.