title: Data upload in a dropdown via Ajax in different dropdowns
body: <p>I have this two dropdowns; by using Ajax I send to my <strong>servlet</strong> a request to get some data from my database and then I need to display those datas into those dropdowns.
  I'm getting those data like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;!-- Required meta tags --&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;header&gt;
  
      &lt;/header&gt;
  
      &lt;section&gt;
          &lt;div id="body-wrapper"&gt;
              &lt;div class="borderedCourseOperations"&gt;
                  &lt;!-- DELETE COURSE --&gt;
                  &lt;h2 id="deleteCourseH2"&gt;Delete a course I&lt;/h2&gt;
                  &lt;div&gt;
                      &lt;select id="coursesOptions" class="custom-select my-1 mr-sm-2"&gt;
                          &lt;option value="" disabled selected&gt;Select a course&lt;/option&gt;
                          &lt;option&gt;2&lt;/option&gt;
                          &lt;option&gt;3&lt;/option&gt;
  
                      &lt;/select&gt;
                      &lt;button id="deleteCourseBtn" type="submit" class="search-btn"&gt;Delete&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;!-- END OF COURSES PANEL --&gt;
              &lt;div class="borderedCourseOperations"&gt;
                  &lt;!-- DELETE COURSE --&gt;
                  &lt;h2 id="deleteCourseH2"&gt;Delete a course II&lt;/h2&gt;
                  &lt;div&gt;
                      &lt;select id="coursesOptionsTwo" class="custom-select my-1 mr-sm-2"&gt;
                          &lt;option value="" disabled selected&gt;Select a course&lt;/option&gt;
                          &lt;option&gt;2&lt;/option&gt;
                          &lt;option&gt;3&lt;/option&gt;
                      &lt;/select&gt;
                      &lt;button id="deleteCourseBtnTwo" type="submit" class="search-btn"&gt;Delete&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
      &lt;/section&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <pre><code>$("#coursesOptions").click(function () {
      $.ajax({
          type: 'GET',
          cache: false,
          url: 'ServletController',
          data: {
              action: "show_courses",
              option: "association"
          },
          success: function (data) {
              courses = JSON.parse(data);
              var option;
              $("#coursesOptions").empty();
              for (var i in courses) {
                  option = '&lt;option data-id = ' + courses[i].id + '&gt;' + courses[i].courseName + '&lt;/option&gt;';
                  $("#coursesOptions").append(option);
              }
          }
      });
  });
  </code></pre>
  
  <p>The fact is that my dropdown doesn't display datas in the right way. What I expect is that when user click on the dropdown - data are shown; but what happens is that when I click on dropdown, data are uploaded into the dropdown but I can only pick the first value. If I try to click on other values it auto-sets only the first one or sometimes not even the first one. I also have to click at least 2 times on the dropdown to be able to see all the datas. What am I droing wrong? Maybe I shouldn't use </p>
  
  <pre><code>$(#).click(function () {}); 
  </code></pre>
  
  <p>And also - If I have different dropdowns that needs to use this Aajx method (but only when they are clicked), is there any way to write it once and call it where is necessary? I've tried to write a javascript function which receive the <strong>select</strong> id as argument and then I tried to paste as body of the function the Ajax method I posted above .... didn't work! </p>
  
  <p>P.s. I apologize if I don't use an appropriate language but I have just started using Ajax, jQuery and JavaScript.</p>