AJAX sub-menu not working in DIV tab

AJAX sub-menu not working in DIV tab

After I added the div tab, the AJAX sub-menu is not working anymore. I am stuck here for whole day.

  1. <div class="tab">
  2. <button class="tablinks" onclick="openProgram(event, 'add_item')" id="defaultOpen">Add Item</button>
  3. <button class="tablinks" onclick="openProgram(event, 'list_item')">List Items</button>
  4. </div>

  5. <!-------------------------------------------------------------------------------------------------------------------------------->
  6. <div id="add_item" class="tabcontent">


  7. <div id="list_item" class="tabcontent">
  8. ...
  9. //not working here
  10. echo '<select name="listcategory" onchange="showsubcat(this.value)">';
  11. foreach ($categoryRows as $categoryRow){
  12. echo '<option value="' . $categoryRow['id'] . '">' . $categoryRow['category_name'] . '</option>';
  13. }
  14. echo '</select>';
  15. echo '<div id="subcatchooser"><b>No Subcategory</b></div>';
  16. //not working here

  1. <script>

  2. function showsubcat(str) {
  3.     if (str.length == 0) { 
  4.         document.getElementById("subcatchooser").innerHTML = "";
  5.         return;
  6.     } else {
  7.         var xmlhttp = new XMLHttpRequest();
  8.         xmlhttp.onreadystatechange = function() {
  9.             if (this.readyState == 4 && this.status == 200) {
  10.                 document.getElementById("subcatchooser").innerHTML = this.responseText;
  11.             }
  12.         };
  13.         xmlhttp.open("GET", "ajax.php?action=showsubcat&parent_id=" + str, true);
  14.         xmlhttp.send();
  15.     }
  16. }

  17. </script>
thx