简体   繁体   中英

How to trigger the native select box using SelectBoxIt jquery plugin

I have used SelectBoxIt plugin to display the select boxes in my application.

I have two select boxes, if I change the value in first select box, another should automatically update (it should trigger automatically).

For both select boxes values are passing dynamically, I used below code

$('.ember-select').selectBoxIt({
            theme: "default",
            autoWidth: false,
            triggerChangeCombined: true
        });

i used

$('.ember-select').selectBoxIt({
            native: true
        });

it will trigger but the slectbox other properties like "theme","autoWidth" are not rendering.

Ok You can check this Demo and code below:

Here is your sample HTML

<div class='formArea'>
    <label>Mode:</label><br/>
    <select id="modes" name="modes">
        <option disabled selected>
            -- Choose a Mode --
         </option>
         <option>Vehicle</option>
         <option>Fleet</option>
         <option>Trailers</option>
     </select><br/>
    <label>Options:</label><br/>
    <select id="optionss" name="optionss">
        <option disabled selected>
            -- Options --
        </option>

     </select><br/>
</div>

Below is your JS:

var vehicles = ['Vehicle 1', 'Vehicle 2', 'Vehicle 3', 'Vehicle 4', 'Vehicle 5']; //add all your vehicle options here
var fleet = ['fleet 1', 'fleet 2', 'fleet 3', 'fleet 4', 'fleet 5']; //add all your fleet options here
var trailers = ['trailer 1', 'trailer 2', 'trailer 3', 'trailer 4', 'trailer 5']; //add all your trailers options here

var optionss =  [{name: "Vehicles", clubs: vehicles},
                 {name: "Fleet", clubs: fleet},
                 {name: "Trailers", clubs: trailers}
                ];


$(function() {
    var selectedmode = $('#modes option:selected').text()
    var optionmenu = $('#optionss');
    for (var i = 0; i < optionss.length; i++) {
         if (selectedmode === optionss[i].name) {
              $.each(optionss, function(val, obj) {
                  optionmenu.append($('<option></option>').val(val).html(obj.clubs));
              });
         }
    }
});

$('#modes').on('change',function(){
    var mode=$(this).find(":selected").text();
    $('#optionss').find('option').remove();
    switch(mode)
    {
        case 'Vehicles':
            $.each(vehicles, function(key, value) {   
                    $('#optionss')
                    .append($("<option></option>")
                    .text(value)); 
            });
            break;

        case 'Fleet':
            $.each(fleet, function(key, value) {   
                    $('#optionss')
                    .append($("<option></option>")
                    .text(value)); 
            });
            break;
        case 'Trailers':
            $.each(trailers, function(key, value) {   
                    $('#optionss')
                    .append($("<option></option>")
                    .text(value)); 
            });
            break;
        default:break;        
      }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM