jQuery-Plugin – select box manipulation

TexoTela has a nice jQuery plugin to manipulate select boxes. You are able to add, remove and sort options with his plugin.

Well, that wasn’t the feature I needed. I needed a plugin to select a specific option via JavaScript. The option(s) should be selected by value. So I have extended the plugin with the functionality to select an option by value:


$("#myselect").selectOptions("val1");

The code can be found here.

19 Kommentare zu “jQuery-Plugin – select box manipulation

  1. I am trying to use this code to select an option based on the Body ID.

    My code looks like this –

    $(document).ready(function() {

    var home = ‘ Corporate Cars ‘;
    var airport = ‘ Airport Transfers ‘;
    var tours = ‘ Tours ‘;
    var group = ‘ Group Transfers ‘;

    // Get the bodyid of the page
    var bodyid = $(“body”).attr(“id”);

    if (bodyid == ‘home’) {
    $(‘#fm_refer’).selectOptions( home );
    }

    else if (bodyid == ‘airport’) {
    $(‘#fm_refer’).selectOptions( airport );
    }

    else if (bodyid == ‘tours’) {
    $(‘#fm_refer’).selectOptions( tours );
    }

    else if (bodyid == ‘group’) {
    $(‘#fm_refer’).selectOptions( group );
    }

    });

    I can populate a text field ok but select boxes are a lot harder!

  2. hello there,

    you’re part of work for TexoTela’s plugin for jQuery is excellent. i’m using it in a small project for myself. currently i’ve got a problem i couldn’t solve until now.

    i’m using xmlhttp-requests to manipulate select-boxes. in dependency of a specific value the boxes are refilled with a reduced set of options. this works very fine.

    now the problem: using firefox as browser, the box is shown with the first value of the database query as expected. but i’m not able to get this behaviour for ie. i’ve tried to select the first value using selectOptions, but neither with the value nor using a regular expression works. ie still shows the last entry of the database query.

    here’s the code:

    function getbox(urlstring, boxname) {
    $(‘#’ + boxname).empty();
    $.get(urlstring, function(data) {
    if (data.length > 0) {
    res_array = data.split(‘|’);
    for (var i = 0; i

  3. sorry, seems that the bracket leads to a problem, once again…
    function getbox(urlstring, boxname) {
    $(‘#’ + boxname).empty();
    $.get(urlstring, function(data) {
    if (data.length GT 0) {
    res_array = data.split(‘|’);
    for (var i = 0; i LT res_array.length; i++) {
    options = res_array[i].split(‘,’);
    opt_val = options[0];
    opt_lbl = options[1];
    $(‘#’ + boxname).addOption(opt_val, opt_lbl);
    $(‘#’ + boxname).selectOptions(opt_lbl, true);
    }
    }
    }
    );
    $(‘#’ + boxname).removeOption(“”);
    $(‘#’ + boxname).selectOptions(“0”);
    }

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.