Skip to main content
Question

ajax request to get values of my drop-down

  • July 21, 2019
  • 0 replies
  • 29 views

I setup a dialog box to select a related option within my table. I managed to create a list of the options which I want to display. I need to know how to enter the values from my list in the dropdown within my dialog box. Thanks

Here is my code:

(function(){

  var dbid = "sample dbid";
  var dbidTasks = "my task table id";
  var dbidOptions = "my options table id";
  var apptoken = "my tokan";
  $.ajaxSetup({data: {apptoken: apptoken}});

 $("a.QBU_Button").on("click", function(event) {

  var relatedTaskType = this.tateset.relatedTaskType;
  var rid = this.dataset.rid;

//this will get a list of options that relate to the related task type
   $.get(dbidOptions, {
      act: "API_DoQuery",
      query: '{11.EX.${rid}}',
      clist: "8.9",
      slist: "7"
    }).then(function(xmlOptions) {

    var markup = "<h1>Select an option:</h1>";
      markup += '
      <select id="QBU_Delay">
        <option value="" selected>Please Select</option>  
        <option value="7">Option 1</option>  //THIS SHOULD BE THE FIRST OPTION FROM MY LIST (FIELD 8) AND THE VALUE SHOULD BE FID 8 OF MY LIST
        <option value="14"> Option 2</option> //THIS SHOULD BE THE SECOND OPTION FROM MY LIST (FIELD 8) AND THE VALUE SHOULD BE FID 8 OF MY LIST and so on
      </select>
      ';

      var $mydialog = $("<div>").html(markup).dialog({
        title: "Options",
        modal: true,
        autoOpen: false,
        width: 400,
resizable: false,
        buttons: {
          'Select And Mark As Done': function() {
           $(this).dialog("close");

          },
          'Just Select': function() {
            $(this).dialog("close");
          }          
        },
        open: function(event, ui) {
          $mydialog.html(markup);
        },
        close: function(event, ui) {
          //do something
        }
      });
      $mydialog.dialog("open");

  });

  });

})();

  • Registered
  • July 22, 2019
This might not be the best way but I like it. I build the html line by line with a loop. You know the ID of your select box already so you just have to clear the innerHTML and then build each option out. You need to get to a point where you have all the information you want to include in the dropdown and then just make it with a loop. "Selection" would be your select/dropdown menu and you would find that by ID and assign it to the variable selection.

I run the next part in a loop that goes over my array of info and builds a select option for each one with this line plus a few others that pull the info from my returned JSON.

selection.innerHTML += "<option value=\"" + recordID + "\">" + name + ": " + description + "</option>";


Hopefully I'm understanding what you are wanting to do here.