How to set a combobox with initial values ? Using javascript / jquery

Asked

Viewed 20 times

1

Hello, I have a code in Go language where we have a web page made in html + javascript + jquery. I need to set the initial values of a combobox according to what is saved in json file. Below follows the function that is called in the javascript code for creating the combobox:

$crudjs.dropdownInput = function(map) {
  return function(value, name, key) {
    return $("<select />")
      .append(Object.keys(map).map(function(key) {
        return $("<option/>")
          .val(key)
          .html(map[key]);
      }))
      .val(value)
      .change(function() {
        if (key) {
          valor = $(this).val();

          if (valor == 0) {
            $crudjs.page.itemField(key, name, "Wifi");


          } else if (valor == 1) {
            $crudjs.page.itemField(key, name, "RF433");

          }

        } else {
          $crudjs.page.field(name, $(this).val());
          mais ");
        }
      });
  }
}

as it is a code that I have already taken ready to modify, I am not managing to evolve in this issue.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.