Forum Discussion

EOMDevelepors's avatar
EOMDevelepors
Qrew Captain
6 years ago

ajax request to get values of my drop-down

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");

  });

  });

})();

  • AustinK's avatar
    AustinK
    Qrew Commander
    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.
    • EOMDevelepors's avatar
      EOMDevelepors
      Qrew Captain
      Thanks for your reply. I am trying to show the options based on my array created in my code called xmlOptions. I just need to view the options from that array and show field 9 and the value should be field 8 which can be passed on later when pressing ok to update the record with that option.

      Thanks again
    • AustinK's avatar
      AustinK
      Qrew Commander
      What exactly is the issue you are having with it? Are you having trouble building the HTML select options form what is returned in DoQuery? I really only use JSON for this so I'm not great with xml.

      There is a really nice Node.js SDK for Quickbase that I enjoy using that has made that easier as it returns JSON by default. I know you are pretty far into it but maybe it would help if you are also more comfortable with JSON. https://github.com/tflanagan/node-quickbase