add option to select combobox

To add option to select you can use :

     $('#selectname').append($("").attr("value", value).text(text));
     $('#selectname').append($("<option></option>").attr("value", value).text(text));
  1. <code>
  2. $('#selectname').append($("<option></option>").attr("value", value).text(text));
  3. </code>
<code>
     $('#selectname').append($("<option></option>").attr("value", value).text(text));
</code>
If you need to append multi value you can user:

    $.each(data, function(i, option) {
        $('#selectname').append($('    $.each(data, function(i, option) {
        $('#selectname').append($('<option>').attr("value", option.id).text(option.name));
    });
</option>
  1. <code>
  2. $.each(data, function(i, option) {
  3. $('#selectname').append($('<option>').attr("value", option.id).text(option.name));
  4. });
  5. </option></code>
<code>
    $.each(data, function(i, option) {
        $('#selectname').append($('<option>').attr("value", option.id).text(option.name));
    });
</option></code>
If you need to add option to first "top" of list use

     $('#sel_bat1').children(":first").before($("").attr("value", value).text(text));
     $('#sel_bat1').children(":first").before($("<option selected="selected"></option>").attr("value", value).text(text));
  1. <code>
  2. $('#sel_bat1').children(":first").before($("<option selected="selected"></option>").attr("value", value).text(text));
  3. </code>
<code>
     $('#sel_bat1').children(":first").before($("<option selected="selected"></option>").attr("value", value).text(text));
</code>

Popular posts from this blog

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

C# Crop white space from around the image

The specified version string contains wildcards, which are not compatible with determinism.